List of usage examples for javax.xml.bind JAXBContext createMarshaller
public abstract Marshaller createMarshaller() throws JAXBException;
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Performs a recursive repository content export with metadata *///from ww w .java 2 s. c o m private static ImpExpStats exportDocumentsHelper(String token, String fldPath, File fs, String metadata, boolean history, Writer out, InfoDecorator deco) throws FileNotFoundException, PathNotFoundException, AccessDeniedException, RepositoryException, IOException, DatabaseException, ParseException, NoSuchGroupException, MessagingException { log.debug("exportDocumentsHelper({}, {}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, fs, metadata, history, out, deco }); ImpExpStats stats = new ImpExpStats(); DocumentModule dm = ModuleManager.getDocumentModule(); FolderModule fm = ModuleManager.getFolderModule(); MailModule mm = ModuleManager.getMailModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Gson gson = new Gson(); String path = null; File fsPath = null; if (firstTime) { path = fs.getPath(); fsPath = new File(path); firstTime = false; } else { // Repository path needs to be "corrected" under Windoze path = fs.getPath() + File.separator + PathUtils.getName(fldPath).replace(':', '_'); fsPath = new File(path); fsPath.mkdirs(); FileLogger.info(BASE_NAME, "Created folder ''{0}''", fsPath.getPath()); if (out != null) { out.write(deco.print(fldPath, 0, null)); out.flush(); } } for (Iterator<Mail> it = mm.getChildren(token, fldPath).iterator(); it.hasNext();) { Mail mailChild = it.next(); path = fsPath.getPath() + File.separator + PathUtils.getName(mailChild.getPath()).replace(':', '_'); ImpExpStats mailStats = exportMail(token, mailChild.getPath(), path + ".eml", metadata, out, deco); // Stats stats.setSize(stats.getSize() + mailStats.getSize()); stats.setMails(stats.getMails() + mailStats.getMails()); } for (Iterator<Document> it = dm.getChildren(token, fldPath).iterator(); it.hasNext();) { Document docChild = it.next(); path = fsPath.getPath() + File.separator + PathUtils.getName(docChild.getPath()).replace(':', '_'); ImpExpStats docStats = exportDocument(token, docChild.getPath(), path, metadata, history, out, deco); // Stats stats.setSize(stats.getSize() + docStats.getSize()); stats.setDocuments(stats.getDocuments() + docStats.getDocuments()); } for (Iterator<Folder> it = fm.getChildren(token, fldPath).iterator(); it.hasNext();) { Folder fldChild = it.next(); ImpExpStats tmp = exportDocumentsHelper(token, fldChild.getPath(), fsPath, metadata, history, out, deco); path = fsPath.getPath() + File.separator + PathUtils.getName(fldChild.getPath()).replace(':', '_'); // Metadata if (metadata.equals("JSON")) { FolderMetadata fmd = ma.getMetadata(fldChild); String json = gson.toJson(fmd); FileOutputStream fos = new FileOutputStream(path + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); fos.close(); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(path + ".xml"); FolderMetadata fmd = ma.getMetadata(fldChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(FolderMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(fmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } // Stats stats.setSize(stats.getSize() + tmp.getSize()); stats.setDocuments(stats.getDocuments() + tmp.getDocuments()); stats.setFolders(stats.getFolders() + tmp.getFolders() + 1); stats.setOk(stats.isOk() && tmp.isOk()); } log.debug("exportDocumentsHelper: {}", stats); return stats; }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
private static void writeAsterixConfigurationFile(AsterixInstance asterixInstance) throws IOException, JAXBException { String asterixInstanceName = asterixInstance.getName(); Cluster cluster = asterixInstance.getCluster(); String metadataNodeId = asterixInstance.getMetadataNodeId(); AsterixConfiguration configuration = asterixInstance.getAsterixConfiguration(); configuration.setInstanceName(asterixInstanceName); configuration.setMetadataNode(asterixInstanceName + "_" + metadataNodeId); String storeDir = null;/*from w w w .j ava2s . c om*/ List<Store> stores = new ArrayList<Store>(); for (Node node : cluster.getNode()) { storeDir = node.getStore() == null ? cluster.getStore() : node.getStore(); stores.add(new Store(asterixInstanceName + "_" + node.getId(), storeDir)); } configuration.setStore(stores); List<Coredump> coredump = new ArrayList<Coredump>(); String coredumpDir = null; List<TransactionLogDir> txnLogDirs = new ArrayList<TransactionLogDir>(); String txnLogDir = null; for (Node node : cluster.getNode()) { coredumpDir = node.getLogDir() == null ? cluster.getLogDir() : node.getLogDir(); coredump.add(new Coredump(asterixInstanceName + "_" + node.getId(), coredumpDir + File.separator + asterixInstanceName + "_" + node.getId())); txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir(); txnLogDirs.add(new TransactionLogDir(asterixInstanceName + "_" + node.getId(), txnLogDir)); } configuration.setCoredump(coredump); configuration.setTransactionLogDir(txnLogDirs); File asterixConfDir = new File(AsterixEventService.getAsterixDir() + File.separator + asterixInstanceName); asterixConfDir.mkdirs(); JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class); Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); FileOutputStream os = new FileOutputStream(asterixConfDir + File.separator + ASTERIX_CONFIGURATION_FILE); marshaller.marshal(configuration, os); os.close(); }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Export document from openkm repository to filesystem. *///from w ww. ja v a 2 s .c om public static ImpExpStats exportDocument(String token, String docPath, String destPath, String metadata, boolean history, Writer out, InfoDecorator deco) throws PathNotFoundException, RepositoryException, DatabaseException, IOException, AccessDeniedException, ParseException, NoSuchGroupException { DocumentModule dm = ModuleManager.getDocumentModule(); MetadataAdapter ma = MetadataAdapter.getInstance(token); Document docChild = dm.getProperties(token, docPath); Gson gson = new Gson(); ImpExpStats stats = new ImpExpStats(); // Version history if (history) { // Create dummy document file new File(destPath).createNewFile(); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); FileOutputStream fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } for (Version ver : dm.getVersionHistory(token, docChild.getPath())) { String versionPath = destPath + "#v" + ver.getName() + "#"; FileOutputStream vos = new FileOutputStream(versionPath); InputStream vis = dm.getContentByVersion(token, docChild.getPath(), ver.getName()); IOUtils.copy(vis, vos); IOUtils.closeQuietly(vis); IOUtils.closeQuietly(vos); FileLogger.info(BASE_NAME, "Created document ''{0}'' version ''{1}''", docChild.getPath(), ver.getName()); // Metadata if (metadata.equals("JSON")) { VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); String json = gson.toJson(vmd); vos = new FileOutputStream(versionPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, vos); IOUtils.closeQuietly(vos); } else if (metadata.equals("XML")) { FileOutputStream fos = new FileOutputStream(destPath + ".xml"); VersionMetadata vmd = ma.getMetadata(ver, docChild.getMimeType()); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(VersionMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(vmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } } else { FileOutputStream fos = new FileOutputStream(destPath); InputStream is = dm.getContent(token, docChild.getPath(), false); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); FileLogger.info(BASE_NAME, "Created document ''{0}''", docChild.getPath()); // Metadata if (metadata.equals("JSON")) { DocumentMetadata dmd = ma.getMetadata(docChild); String json = gson.toJson(dmd); fos = new FileOutputStream(destPath + Config.EXPORT_METADATA_EXT); IOUtils.write(json, fos); IOUtils.closeQuietly(fos); } else if (metadata.equals("XML")) { fos = new FileOutputStream(destPath + ".xml"); DocumentMetadata dmd = ma.getMetadata(docChild); JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(DocumentMetadata.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(dmd, fos); } catch (JAXBException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "XMLException ''{0}''", e.getMessage()); } } } if (out != null) { out.write(deco.print(docChild.getPath(), docChild.getActualVersion().getSize(), null)); out.flush(); } // Stats stats.setSize(stats.getSize() + docChild.getActualVersion().getSize()); stats.setDocuments(stats.getDocuments() + 1); return stats; }
From source file:labr_client.xml.ObjToXML.java
public static void jaxbObjectToXML(KmehrMessage kmehrMessage) { try {/* w w w . j a v a2 s.c om*/ JAXBContext context = JAXBContext.newInstance(KmehrMessage.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //----------HEADER-------------------------- kmehrMessage.header.id.setS("ID-KMEHR"); kmehrMessage.header.id.setSV("1.15"); kmehrMessage.header.id.setValue("0000000"); kmehrMessage.header.setDate("20160519"); kmehrMessage.header.setTime("09:40:31"); kmehrMessage.header.standard.cd.setS("CD-STANDARD"); kmehrMessage.header.standard.cd.setSV("1.15"); kmehrMessage.header.standard.cd.setValue("20150901"); //----------HEADER-ZENDER------------------------- kmehrMessage.header.sender.hcparty.id.setS("ID-HCPARTY"); kmehrMessage.header.sender.hcparty.id.setSV("1.15"); kmehrMessage.header.sender.hcparty.id.setValue("000000"); kmehrMessage.header.sender.hcparty.cd.setS("CD-HCPARTY"); kmehrMessage.header.sender.hcparty.cd.setSV("1.15"); kmehrMessage.header.sender.hcparty.cd.setValue("persphysician"); kmehrMessage.header.sender.hcparty.setFamilyname("Pieters"); kmehrMessage.header.sender.hcparty.setFirstname("Piet"); //----------HEADER-ONTVANGER(S)-------------------- Hcparty receiver = new Hcparty(); receiver.id.setS("ID-HCPARTY"); receiver.id.setSV("1.15"); receiver.id.setValue("000000"); receiver.cd.setS("CD-HCPARTY"); receiver.cd.setSV("1.15"); receiver.cd.setValue("persphysician"); receiver.setFamilyname("Pieters"); receiver.setFirstname("Piet"); kmehrMessage.header.receiver.getHcparty().add(receiver); //----------FOLDER------------------------- kmehrMessage.folder.id.setS("ID-HCPARTY"); kmehrMessage.folder.id.setSV("1.15"); kmehrMessage.folder.patient.setFamilyname("De Mey"); kmehrMessage.folder.patient.setFirstname("Matthias"); kmehrMessage.folder.patient.birthdate.setDate("1990/06/07"); kmehrMessage.setXmlns("http://www.ehealth.fgov.be/standards/kmehr/schema/v1"); m.marshal(kmehrMessage, new File("C:\\Users\\labbl\\Documents\\testKMEHR.xml")); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:org.pentaho.platform.dataaccess.datasource.DataSourcePublishACLTest.java
private static String marshalACL(RepositoryFileAclDto acl) throws JAXBException { JAXBContext context = JAXBContext.newInstance(RepositoryFileAclDto.class); Marshaller marshaller = context.createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(acl, sw);//from w w w . j av a 2s . c o m return sw.toString(); }
From source file:labr_client.xml.ObjToXML.java
public static void jaxbObjectToXML(LabrRequest request, HashMap<String, String> patient) { try {//from w w w . j av a 2s . c o m JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //----------PATIENT---------------------------- request.patient.name.setValue("De Mey"); request.patient.name.setX(20); request.patient.name.setY(50); request.patient.firstName.setValue("Matthias"); request.patient.firstName.setX(150); request.patient.firstName.setY(50); request.patient.birthDate.setValue("07/06/1990"); request.patient.birthDate.setX(20); request.patient.birthDate.setY(80); request.patient.gender.setValue("M"); request.patient.gender.setX(150); request.patient.gender.setY(80); request.patient.straatAndNumber.setValue("Hemelbeekstraat 16"); request.patient.straatAndNumber.setX(20); request.patient.straatAndNumber.setY(110); request.patient.zip.setValue("8000"); request.patient.zip.setX(20); request.patient.zip.setY(140); request.patient.city.setValue("Brugge"); request.patient.city.setX(120); request.patient.city.setY(140); request.patient.country.setValue("Belgie"); request.patient.country.setX(20); request.patient.country.setY(170); request.patient.nationalNumber.setValue("001-12345-223"); request.patient.nationalNumber.setX(120); request.patient.nationalNumber.setY(210); //----------ATTRIBUTEN------------------------- request.attributes.setAge(26); //----------LABELS----------------------------- LabrXMLLabel l = new LabrXMLLabel(); l.setColor("#110000"); l.setSize(12); l.setId("1"); l.setValue("Hematologie"); request.labels.getLabel().add(l); //---------KNOPPEN----------------------------- request.buttons.save.setX(300); request.buttons.save.setY(100); request.buttons.save.setColor(-65536); request.buttons.save.setWidth(100); request.buttons.save.setValue("Save"); //----------AANVRAGEN-------------------------- LabrXMLRequest r = new LabrXMLRequest(); r.setComment("Dit is commentaar"); r.setLoinc("Kalium"); request.requests.getRequest().add(r); r.setLoinc("Natrium"); request.requests.getRequest().add(r); //----------AANVRAGEN-------------------------- // Write to System.out for debugging // m.marshal(emp, System.out); // Write to File m.marshal(request, new File("C:\\Users\\labbl\\Documents\\test.xml")); } catch (JAXBException e) { e.printStackTrace(); } }
From source file:com.jkoolcloud.tnt4j.streams.utils.StreamsCache.java
private static void persist(Map<String, CacheValue> cacheEntries) { try {//from www . j a va 2 s .c om JAXBContext jc = JAXBContext.newInstance(CacheRoot.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); CacheRoot root = new CacheRoot(); root.setEntriesMap(cacheEntries); File persistedFile = new File(DEFAULT_FILE_NAME); LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.file", persistedFile.getAbsolutePath()); marshaller.marshal(root, persistedFile); LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.done", cacheEntries.size(), persistedFile.getAbsolutePath()); } catch (JAXBException exc) { Utils.logThrowable(LOGGER, OpLevel.ERROR, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME), "StreamsCache.persisting.failed", exc); } }
From source file:labr_client.xml.ObjToXML.java
public static void saveProfile(Component[] comps, String profile) { try {/*from ww w . j ava2s . c o m*/ if (comps != null) { JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); LabrRequest request = new LabrRequest(); for (Component comp : comps) { if (comp.getName() != null) { if (comp.getName().equals("name")) { request.patient.name.setValue(((JTextField) comp).getText()); request.patient.name.setX(comp.getX()); request.patient.name.setY(comp.getY()); request.patient.name.setWidth(comp.getWidth()); } else if (comp.getName().equals("firstName")) { request.patient.firstName.setValue(((JTextField) comp).getText()); request.patient.firstName.setX(comp.getX()); request.patient.firstName.setY(comp.getY()); request.patient.firstName.setWidth(comp.getWidth()); } else if (comp.getName().equals("birthDate")) { request.patient.birthDate.setValue(((JFormattedTextField) comp).getText()); request.patient.birthDate.setX(comp.getX()); request.patient.birthDate.setY(comp.getY()); request.patient.birthDate.setWidth(comp.getWidth()); } else if (comp.getName().equals("gender")) { request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.gender.setX(comp.getX()); request.patient.gender.setY(comp.getY()); } else if (comp.getName().equals("straatAndNumber")) { request.patient.straatAndNumber.setValue(((JTextField) comp).getText()); request.patient.straatAndNumber.setX(comp.getX()); request.patient.straatAndNumber.setY(comp.getY()); request.patient.straatAndNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("zip")) { request.patient.zip.setValue(((JTextField) comp).getText()); request.patient.zip.setX(comp.getX()); request.patient.zip.setY(comp.getY()); request.patient.zip.setWidth(comp.getWidth()); } else if (comp.getName().equals("city")) { request.patient.city.setValue(((JTextField) comp).getText()); request.patient.city.setX(comp.getX()); request.patient.city.setY(comp.getY()); request.patient.city.setWidth(comp.getWidth()); } else if (comp.getName().equals("country")) { request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.country.setX(comp.getX()); request.patient.country.setY(comp.getY()); } else if (comp.getName().equals("nationalNumber")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("Save")) { JButton jbut = (JButton) comp; ImageIcon icon = (ImageIcon) jbut.getIcon(); request.buttons.save.setX(comp.getX()); request.buttons.save.setY(comp.getY()); request.buttons.save.setValue("Save"); if (icon != null) { request.buttons.save.setIcon(icon.getDescription()); } } else if (comp.getName().equals("Search")) { } else if (comp.getName().equals("saveAndSend")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("print")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else { Class<? extends Component> c = comp.getClass(); if (c.getSimpleName().equals("JLabel")) { JLabel lbl = (JLabel) comp; LabrXMLLabel l = new LabrXMLLabel(); l.setColor(String.valueOf(lbl.getForeground().getRGB())); l.setSize(lbl.getFont().getSize()); l.setId(lbl.getName()); l.setValue(lbl.getText()); l.setX(lbl.getX()); l.setY(lbl.getY()); request.labels.getLabel().add(l); } ; if (c.getSimpleName().equals("JCheckBox")) { JCheckBox chbx = (JCheckBox) comp; LabrXMLRequest req = new LabrXMLRequest(); req.setX(chbx.getX()); req.setY(chbx.getY()); req.setLoinc(chbx.getName()); req.setValue(chbx.getText()); req.setSelected(chbx.isSelected()); request.requests.getRequest().add(req); } ; if (c.getSimpleName().equals("JTextBox")) { } ; } } } m.marshal(request, new File(PublicVars.getUserData()[9] + "\\" + profile + ".xml")); } } catch (JAXBException e) { e.printStackTrace(); } }
From source file:labr_client.xml.ObjToXML.java
public static void saveKmehrRequest(LabrRequest request) { String date = String.format("%1$tY%1$tm%1$td", new Date()); String time = String.format("%1$tH%1$tM%1$tS", new Date()); try {//from w w w .ja v a 2s . co m KmehrMessage kmehrMessage = new KmehrMessage(); JAXBContext context = JAXBContext.newInstance(KmehrMessage.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //----------HEADER-------------------------- kmehrMessage.header.id.setS("ID-KMEHR"); kmehrMessage.header.id.setSV("1.15"); kmehrMessage.header.id.setValue(request.attributes.getTitle()); kmehrMessage.header.setDate(date); kmehrMessage.header.setTime(time); kmehrMessage.header.standard.cd.setS("CD-STANDARD"); kmehrMessage.header.standard.cd.setSV("1.15"); kmehrMessage.header.standard.cd.setValue("20150901"); //----------HEADER-ZENDER------------------------- kmehrMessage.header.sender.hcparty.id.setS("ID-HCPARTY"); kmehrMessage.header.sender.hcparty.id.setSV("1.15"); kmehrMessage.header.sender.hcparty.id.setValue(request.attributes.getSenderID()); kmehrMessage.header.sender.hcparty.cd.setS("CD-HCPARTY"); kmehrMessage.header.sender.hcparty.cd.setSV("1.15"); kmehrMessage.header.sender.hcparty.cd.setValue("persphysician"); kmehrMessage.header.sender.hcparty.setFamilyname("Pieters"); kmehrMessage.header.sender.hcparty.setFirstname("Piet"); //----------HEADER-ONTVANGER(S)-------------------- Hcparty receiver = new Hcparty(); receiver.id.setS("ID-HCPARTY"); receiver.id.setSV("1.15"); receiver.id.setValue(request.attributes.receiver1ID); receiver.cd.setS("CD-HCPARTY"); receiver.cd.setSV("1.15"); receiver.cd.setValue("persphysician"); receiver.setFamilyname("Pieters"); receiver.setFirstname("Piet"); kmehrMessage.header.receiver.getHcparty().add(receiver); //----------FOLDER-PATIENT------------------------- kmehrMessage.folder.id.setS("ID-HCPARTY"); kmehrMessage.folder.id.setSV("1.15"); kmehrMessage.folder.id.setValue(request.patient.nationalNumber.getValue()); kmehrMessage.folder.patient.setFamilyname(request.patient.name.getValue()); kmehrMessage.folder.patient.setFirstname(request.patient.firstName.getValue()); kmehrMessage.folder.patient.birthdate.setDate(request.patient.birthDate.getValue()); kmehrMessage.folder.patient.sex.cd.setS("CD-SEX"); kmehrMessage.folder.patient.sex.cd.setSV("1.15"); kmehrMessage.folder.patient.sex.cd.setValue("M"); kmehrMessage.folder.patient.address.cd.setS("CD-ADDRESS"); kmehrMessage.folder.patient.address.cd.setSV("1.15"); kmehrMessage.folder.patient.address.country.cd.setS("CD-COUNTRY"); kmehrMessage.folder.patient.address.country.cd.setSV("1.15"); kmehrMessage.folder.patient.address.country.cd.setValue(request.patient.country.getValue()); kmehrMessage.folder.patient.address.setCity(request.patient.city.getValue()); kmehrMessage.folder.patient.address.setStreetandnumber(request.patient.straatAndNumber.getValue()); kmehrMessage.folder.patient.address.setZip(request.patient.zip.getValue()); Transaction t = new Transaction(); t.id.setS("ID-KMEHR"); t.id.setSV("1.15"); t.id.setValue("1"); t.cd.setS("CD-TRANSACTION"); t.cd.setSV("1.15"); t.cd.setValue("request"); t.setDate(date); t.setTime(time); t.author.hcparty.id.setS("ID-HCPARTY"); t.author.hcparty.id.setSV("1.15"); t.author.hcparty.id.setValue(request.attributes.getSenderID()); t.author.hcparty.cd.setS("CD-HCPARTY"); t.author.hcparty.cd.setSV("1.15"); t.author.hcparty.cd.setValue("persphysician"); t.author.hcparty.setFamilyname("Pieters"); t.author.hcparty.setFirstname("Piet"); Item i = new Item(); i.id.setS("ID-KMEHR"); i.id.setSV("1.15"); i.id.setValue("1"); i.cd.setS("CD-ITEM"); i.cd.setSV("1.15"); i.cd.setValue("lab"); List<LabrXMLRequest> requests = request.requests.getRequest(); for (LabrXMLRequest req : requests) { if (req.isSelected() & req.getLoinc() != null) { Cd cd = new Cd(); cd.setS("CD-LAB"); cd.setSV("1.15"); cd.setValue(req.getLoinc()); i.content.getCd().add(cd); } } t.getItem().add(i); kmehrMessage.folder.getTransaction().add(t); kmehrMessage.setXmlns("http://www.ehealth.fgov.be/standards/kmehr/schema/v1"); //START------ZOEK DE PATIENT OP EN BEWAAR AANVRAAG IN DATABASE------------------------- File KmehrRequest = new File("data/tmp/" + date + time + ".xml"); m.marshal(kmehrMessage, KmehrRequest); List<String[]> patientID = PublicVars.getQueries().selectPatient(request.patient.firstName.getValue(), request.patient.name.getValue(), request.patient.birthDate.getValue()); if (patientID.size() == 0) { PublicVars.getQueries().insertPatient(request); patientID = PublicVars.getQueries().selectPatient(request.patient.firstName.getValue(), request.patient.name.getValue(), request.patient.birthDate.getValue()); PublicVars.getQueries().insertLabRequest(marshallRequest(request), FileUtils.readFileToString(KmehrRequest), Integer.parseInt(patientID.get(0)[0]), Integer.parseInt(PublicVars.getUserData()[1]), kmehrMessage.header.id.getValue()); } else { PublicVars.getQueries().insertLabRequest(marshallRequest(request), FileUtils.readFileToString(KmehrRequest), Integer.parseInt(patientID.get(0)[0]), Integer.parseInt(PublicVars.getUserData()[1]), kmehrMessage.header.id.getValue()); } //EIND--------------------------------------------------------------------------------- } catch (JAXBException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ObjToXML.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:labr_client.xml.ObjToXML.java
public static LabrRequest saveLabrRequest(Component[] comps) { try {/*from w w w . ja va 2 s. c o m*/ if (comps != null) { JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); LabrRequest request = new LabrRequest(); for (Component comp : comps) { if (comp.getName() != null) { if (comp.getName().equals("name")) { request.patient.name.setValue(((JTextField) comp).getText()); request.patient.name.setX(comp.getX()); request.patient.name.setY(comp.getY()); request.patient.name.setWidth(comp.getWidth()); } else if (comp.getName().equals("firstName")) { request.patient.firstName.setValue(((JTextField) comp).getText()); request.patient.firstName.setX(comp.getX()); request.patient.firstName.setY(comp.getY()); request.patient.firstName.setWidth(comp.getWidth()); } else if (comp.getName().equals("birthDate")) { request.patient.birthDate.setValue(((JFormattedTextField) comp).getText()); request.patient.birthDate.setX(comp.getX()); request.patient.birthDate.setY(comp.getY()); request.patient.birthDate.setWidth(comp.getWidth()); } else if (comp.getName().equals("gender")) { request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.gender.setX(comp.getX()); request.patient.gender.setY(comp.getY()); } else if (comp.getName().equals("straatAndNumber")) { request.patient.straatAndNumber.setValue(((JTextField) comp).getText()); request.patient.straatAndNumber.setX(comp.getX()); request.patient.straatAndNumber.setY(comp.getY()); request.patient.straatAndNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("zip")) { request.patient.zip.setValue(((JTextField) comp).getText()); request.patient.zip.setX(comp.getX()); request.patient.zip.setY(comp.getY()); request.patient.zip.setWidth(comp.getWidth()); } else if (comp.getName().equals("city")) { request.patient.city.setValue(((JTextField) comp).getText()); request.patient.city.setX(comp.getX()); request.patient.city.setY(comp.getY()); request.patient.city.setWidth(comp.getWidth()); } else if (comp.getName().equals("country")) { request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.country.setX(comp.getX()); request.patient.country.setY(comp.getY()); } else if (comp.getName().equals("nationalNumber")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("Save")) { JButton jbut = (JButton) comp; ImageIcon icon = (ImageIcon) jbut.getIcon(); request.buttons.save.setX(comp.getX()); request.buttons.save.setY(comp.getY()); request.buttons.save.setValue("Save"); if (icon != null) { request.buttons.save.setIcon(icon.getDescription()); } } else if (comp.getName().equals("Search")) { } else if (comp.getName().equals("saveAndSend")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("print")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else { Class<? extends Component> c = comp.getClass(); if (c.getSimpleName().equals("JLabel")) { JLabel lbl = (JLabel) comp; LabrXMLLabel l = new LabrXMLLabel(); l.setColor(String.valueOf(lbl.getForeground().getRGB())); l.setSize(lbl.getFont().getSize()); l.setId(lbl.getName()); l.setValue(lbl.getText()); l.setX(lbl.getX()); l.setY(lbl.getY()); request.labels.getLabel().add(l); } ; if (c.getSimpleName().equals("JCheckBox")) { JCheckBox chbx = (JCheckBox) comp; LabrXMLRequest req = new LabrXMLRequest(); req.setX(chbx.getX()); req.setY(chbx.getY()); req.setLoinc(chbx.getName()); req.setValue(chbx.getText()); req.setSelected(chbx.isSelected()); request.requests.getRequest().add(req); } ; if (c.getSimpleName().equals("JTextBox")) { } ; } } } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm"); String date = dateFormat.format(Calendar.getInstance().getTime()); request.attributes.setTitle("LABR-" + PublicVars.getUserData()[5] + "-" + date); return request; } return null; } catch (JAXBException e) { e.printStackTrace(); return null; } }