List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:labr_client.xml.ObjToXML.java
public static LabrRequest saveLabrRequest(Component[] comps) { try {/*w w w . j av a 2 s .com*/ 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; } }
From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java
public static <T> String marshallToSting(QName elementName, T object, boolean formatted) throws JAXBException { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); if (formatted) { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); }/* w w w . j av a 2 s . co m*/ java.io.StringWriter sw = new StringWriter(); JAXBElement<T> element = new JAXBElement<T>(elementName, (Class<T>) object.getClass(), object); marshaller.marshal(element, sw); return sw.toString(); }
From source file:eu.eco2clouds.scheduler.accounting.client.AccountingClientHC.java
@Override public Experiment updateExperiment(Experiment experiment) { Boolean exception = false;/* www . j a v a2s .c o m*/ String experimentUrl = url + "/experiments/" + experiment.getId().intValue(); logger.debug("URL build: " + experimentUrl); try { JAXBContext jaxbContext = JAXBContext.newInstance(Experiment.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(experiment, out); String payload = out.toString(); String response = putMethod(experimentUrl, payload, experiment.getBonfireUserId(), experiment.getBonfireGroupId(), exception); logger.debug("PAYLOAD: " + response); try { jaxbContext = JAXBContext.newInstance(Experiment.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); experiment = (Experiment) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying incoming experiment to object. Exception: " + e.getMessage()); exception = true; } } catch (JAXBException e) { logger.warn("Error trying to parse returned experiment from database: " + url + "/experiments" + " Exception: " + e.getMessage()); exception = true; } if (exception) return new Experiment(); return experiment; }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.schema.GridRowLoader.java
private void exportFile(List<GridRow> schemaGridRowList, Schema schema) throws JAXBException, PropertyException { JAXBContext jaxbContext;/* w w w. ja va 2 s . c o m*/ jaxbContext = JAXBContext.newInstance(Schema.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); for (GridRow gridRow : schemaGridRowList) { Field field = ExternalSchemaUtil.INSTANCE.convertGridRowToJaxbSchemaField(gridRow); fields.getField().add(field); } schema.setFields(fields); jaxbMarshaller.marshal(schema, schemaFile); }
From source file:esg.node.components.registry.RegistrationGleaner.java
public String toString() { String out = null;//from ww w.j a v a 2 s . c o m if (myRegistration == null) { log.error("Registration is [" + myRegistration + "]"); return null; } log.trace( "Writing registration information to String, for " + myRegistration.getNode().get(0).getHostname()); try { StringWriter sw = new StringWriter(); JAXBContext jc = JAXBContext.newInstance(Registration.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(myRegistration, sw); out = sw.toString(); sync(); //NOTE: Hopefully this isn't to slow... may have to move //to saveRegistration since that would potentially be //called much less often log.trace("Checksumming xml content..."); String lastChecksum = myChecksum; myChecksum = quickHash.sum(sw.toString()); dirty = (!myChecksum.equals(lastChecksum)); log.debug("Checksum of xml string is: " + myChecksum + (dirty ? " (modified)" : " (unchanged")); } catch (Exception e) { log.error(e); } return out; }
From source file:gov.nih.nci.cabig.caaers.esb.client.impl.CtmsCaaersMessageConsumer.java
/** * This method is used to marshal the Response objects from Individual Services to xml format * so that it can be set as the Content of the Response JMS TextMessage * @param pObject/*from w ww. ja v a2 s .co m*/ * @param marshaller * @return * @throws JAXBException */ public String responseAsString(Object pObject, Marshaller marshaller) throws JAXBException { StringWriter sw = new StringWriter(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(pObject, sw); return sw.toString(); }
From source file:com.silverpeas.publicationTemplate.PublicationTemplateImpl.java
/** * Save a recordTemplate to xml file/* www . j a v a 2 s .co m*/ * * @param recordTemplate the object to save as xml File * @param subDir the sub directory where saving the xml file * @param xmlFileName the xml file name * @throws PublicationTemplateException */ private void saveRecordTemplate(RecordTemplate recordTemplate, String subDir, String xmlFileName) throws PublicationTemplateException { // save record into XML file try { // Format this URL String xmlFilePath = PublicationTemplateManager.makePath(PublicationTemplateManager.templateDir, subDir + xmlFileName); Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(recordTemplate, new File(xmlFilePath)); } catch (JAXBException e) { throw new PublicationTemplateException("PublicationTemplateManager.loadPublicationTemplate", "form.EX_ERR_CASTOR_UNMARSHALL_PUBLICATION_TEMPLATE", "Publication Template FileName : " + xmlFileName, e); } }
From source file:com.aionemu.gameserver.dataholders.SpawnsData2.java
public synchronized boolean saveSpawn(Player admin, VisibleObject visibleObject, boolean delete) throws IOException { SpawnTemplate spawn = visibleObject.getSpawn(); Spawn oldGroup = DataManager.SPAWNS_DATA2.getSpawnsForNpc(visibleObject.getWorldId(), spawn.getNpcId()); File xml = new File("./data/static_data/spawns/" + getRelativePath(visibleObject)); SpawnsData2 data = null;/*from ww w. ja va 2 s . c om*/ SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = null; JAXBContext jc = null; boolean addGroup = false; try { schema = sf.newSchema(new File("./data/static_data/spawns/spawns.xsd")); jc = JAXBContext.newInstance(SpawnsData2.class); } catch (Exception e) { // ignore, if schemas are wrong then we even could not call the command; } FileInputStream fin = null; if (xml.exists()) { try { fin = new FileInputStream(xml); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setSchema(schema); data = (SpawnsData2) unmarshaller.unmarshal(fin); } catch (Exception e) { log.error(e.getMessage()); PacketSendUtility.sendMessage(admin, "Could not load old XML file!"); return false; } finally { if (fin != null) { fin.close(); } } } if (oldGroup == null || oldGroup.isCustom()) { if (data == null) { data = new SpawnsData2(); } oldGroup = data.getSpawnsForNpc(visibleObject.getWorldId(), spawn.getNpcId()); if (oldGroup == null) { oldGroup = new Spawn(spawn.getNpcId(), spawn.getRespawnTime(), spawn.getHandlerType()); addGroup = true; } } else { if (data == null) { data = DataManager.SPAWNS_DATA2; } // only remove from memory, will be added back later allSpawnMaps.get(visibleObject.getWorldId()).remove(spawn.getNpcId()); addGroup = true; } SpawnSpotTemplate spot = new SpawnSpotTemplate(visibleObject.getX(), visibleObject.getY(), visibleObject.getZ(), visibleObject.getHeading(), visibleObject.getSpawn().getRandomWalk(), visibleObject.getSpawn().getWalkerId(), visibleObject.getSpawn().getWalkerIndex()); boolean changeX = visibleObject.getX() != spawn.getX(); boolean changeY = visibleObject.getY() != spawn.getY(); boolean changeZ = visibleObject.getZ() != spawn.getZ(); boolean changeH = visibleObject.getHeading() != spawn.getHeading(); if (changeH && visibleObject instanceof Npc) { Npc npc = (Npc) visibleObject; if (!npc.isAtSpawnLocation() || !npc.isInState(CreatureState.NPC_IDLE) || changeX || changeY || changeZ) { // if H changed, XSD validation fails, because it may be negative; thus, reset it back visibleObject.setXYZH(null, null, null, spawn.getHeading()); changeH = false; } } SpawnSpotTemplate oldSpot = null; for (SpawnSpotTemplate s : oldGroup.getSpawnSpotTemplates()) { if (s.getX() == spot.getX() && s.getY() == spot.getY() && s.getZ() == spot.getZ() && s.getHeading() == spot.getHeading()) { if (delete || !StringUtils.equals(s.getWalkerId(), spot.getWalkerId())) { oldSpot = s; break; } else { return false; // nothing to change } } else if (changeX && s.getY() == spot.getY() && s.getZ() == spot.getZ() && s.getHeading() == spot.getHeading() || changeY && s.getX() == spot.getX() && s.getZ() == spot.getZ() && s.getHeading() == spot.getHeading() || changeZ && s.getX() == spot.getX() && s.getY() == spot.getY() && s.getHeading() == spot.getHeading() || changeH && s.getX() == spot.getX() && s.getY() == spot.getY() && s.getZ() == spot.getZ()) { oldSpot = s; break; } } if (oldSpot != null) { oldGroup.getSpawnSpotTemplates().remove(oldSpot); } if (!delete) { oldGroup.addSpawnSpot(spot); } oldGroup.setCustom(true); SpawnMap map = null; if (data.templates == null) { data.templates = new ArrayList<SpawnMap>(); map = new SpawnMap(spawn.getWorldId()); data.templates.add(map); } else { map = data.templates.get(0); } if (addGroup) { map.addSpawns(oldGroup); } FileOutputStream fos = null; try { xml.getParentFile().mkdir(); fos = new FileOutputStream(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setSchema(schema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(data, fos); DataManager.SPAWNS_DATA2.templates = data.templates; DataManager.SPAWNS_DATA2.afterUnmarshal(null, null); DataManager.SPAWNS_DATA2.clearTemplates(); data.clearTemplates(); } catch (Exception e) { log.error(e.getMessage()); PacketSendUtility.sendMessage(admin, "Could not save XML file!"); return false; } finally { if (fos != null) { fos.close(); } } return true; }
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalDeployment.java
/** * gets an XML representation of the model * @return//from w w w .j av a 2 s .co m */ public String dumpXml() { logger.debug("dumping xml model for " + this + " into a String"); JAXBContext jc; try { jc = JAXBContext.newInstance(LogicalDeployment.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(this, baos); return baos.toString(); } catch (JAXBException e) { logger.error("Unable to marshall model"); throw new TechnicalException(e); } }
From source file:com.axelor.controller.ConnectionToPrestashop.java
@SuppressWarnings("null") @Transactional/* ww w . j a va 2 s. c om*/ public void insertCurrency(int currencyId) { com.axelor.pojo.Currency pojoCurrency = new com.axelor.pojo.Currency(); pojoCurrency.setName("NAME"); pojoCurrency.setIso_code("ISO_CODE"); pojoCurrency.setSign("SIGN"); try { System.out.println("Cuurency Id :: " + currencyId); URL url = new URL("http://localhost/client-lib/crud/action.php?resource=currencies&action=retrieve&id=" + currencyId + "&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.Currency.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); connection.setDoOutput(true); connection.setDoInput(true); OutputStream outputStream = connection.getOutputStream(); jaxbMarshaller.marshal(pojoCurrency, outputStream); connection.connect(); //InputStream inputStream = connection.getInputStream(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); pojoCurrency = (com.axelor.pojo.Currency) jaxbUnmarshaller .unmarshal(new UnmarshalInputStream(connection.getInputStream())); // jaxbMarshaller.marshal(pojoCurrency, f); Currency checkCurrency = Currency.all().filter("code=?", pojoCurrency.getIso_code()).fetchOne(); if (checkCurrency != null) { checkCurrency.setPrestashopCurrencyId(currencyId); } else { Currency currency = new Currency(); // add this currency into ERP currency.setName(pojoCurrency.getName()); currency.setCode(pojoCurrency.getIso_code()); currency.setSymbol(pojoCurrency.getSign()); currency.setPrestashopCurrencyId(currencyId); currency.save(); } } catch (Exception e) { System.out.println(e); } }