List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:hydrograph.ui.engine.util.ConverterUtil.java
/** * Store file into local file system./* w ww . j ava2 s . c om*/ * * @param graph * @param externalOutputFile * @param out * @throws CoreException the core exception * @throws JAXBException the JAXB exception * @throws IOException Signals that an I/O exception has occurred. */ private void storeFileIntoLocalFileSystem(Graph graph, boolean validate, IFileStore externalOutputFile, ByteArrayOutputStream out) throws CoreException, JAXBException, IOException { File externalFile = externalOutputFile.toLocalFile(0, null); OutputStream outputStream = new FileOutputStream(externalFile.getAbsolutePath().replace(".job", ".xml")); JAXBContext jaxbContext = JAXBContext.newInstance(graph.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); out = new ByteArrayOutputStream(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(graph, out); out = ComponentXpath.INSTANCE.addParameters(out); out.writeTo(outputStream); outputStream.close(); }
From source file:cz.zcu.kiv.eegdatabase.logic.xml.XMLTransformer.java
public OutputStream transform(Experiment meas, MetadataCommand mc, Set<DataFile> datas) throws JAXBException, IOException { if (meas == null) { return null; }/*from w w w. j a va 2 s . c o m*/ jc = JAXBContext.newInstance(objects); of = new ObjectFactory(); log.debug("Creating JAXB context"); MeasurationType measType = of.createMeasurationType(); XMLMeasuration mea = new XMLMeasuration(measType); if (mc.isTimes()) { mea.writeStartAndEndTime(meas.getStartTime().toString(), meas.getEndTime().toString()); log.debug("Written start and end time: " + measType.getStartTime() + ", " + measType.getEndTime()); } Scenario scenario = meas.getScenario(); ScenarioType scType = of.createScenarioType(); XMLScenario scen = new XMLScenario(scType); if (mc.isTitle()) { scen.writeTitle(scenario.getTitle()); } if (mc.isLength() && scenario.getScenarioLength() >= 0) { scen.writeLength("" + scenario.getScenarioLength() + ResourceUtils.getString("valueTable.scenarioLength.minutes")); } if (mc.isDescription()) { scen.writeDescription(scenario.getDescription()); } measType.setScenario(scType); log.debug("Written Scenario metadata: " + scType); if (mc.isTemperature()) { measType.setTemperature(meas.getTemperature()); } if (mc.isHardware()) { List<HardwareType> hwType = measType.getHardware(); for (Hardware hw : meas.getHardwares()) { hwType.add(mea.writeHardware(hw, of)); log.debug("Written hardware: " + hw); } } if (mc.isMeasurationAddParams()) { List<MeasurationAddParam> param = measType.getAddParam(); for (ExperimentOptParamVal measAddParam : meas.getExperimentOptParamVals()) { param.add(mea.writeAdditionalParams(measAddParam, of)); log.debug("Written measured additional params: " + measAddParam); } } if (mc.isWeather() && meas.getWeather() != null) { WeatherType wType = of.createWeatherType(); wType.setTitle(meas.getWeather().getTitle()); wType.setDescription(meas.getWeather().getDescription()); measType.setWeather(wType); log.debug("Written weather: " + wType); } if (mc.isWeatherNote()) { measType.setEnvironmentNote(meas.getEnvironmentNote()); } List<PersonType> perType = measType.getPerson(); writePerson(perType, meas.getPersonBySubjectPersonId(), measured, mc, meas.getStartTime()); for (Person person : meas.getPersons()) { writePerson(perType, person, experimenter, mc, null); log.debug("Written Person metadata: " + person); } List<DataType> dataType = measType.getData(); if (meas.getDataFiles() != null) { for (DataFile data : datas) { log.debug("creating data into output xml: " + data.getFilename()); DataType datat = of.createDataType(); datat.setFileName(data.getFilename()); if (mc.isSamplingRate()) { datat.setDescription(data.getDescription()); } log.debug("Written file description: " + datat.getDescription()); if (data.getFileMetadataParamVals() != null) { List<FileMetadataType> metType = datat.getFileMetadata(); for (FileMetadataParamVal fileMetadata : data.getFileMetadataParamVals()) { metType.add(mea.writeFileMetadata(fileMetadata, of)); log.debug("Written sampling rate and file metadata: " + fileMetadata); } } dataType.add(datat); } } Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, encoding); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XSDSchema); JAXBElement<MeasurationType> me = of.createMeasuration(measType); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(me, baos); log.debug("Written XML document into a ByteArrayOutputStream "); return baos; }
From source file:cz.lbenda.dataman.db.DbConfig.java
/** Save session conf into File * @param writer writer to which is configuration saved */ public void save(Writer writer) throws IOException { cz.lbenda.dataman.schema.dataman.ObjectFactory of = new cz.lbenda.dataman.schema.dataman.ObjectFactory(); SessionType st = storeToSessionType(null, null); try {//from w w w. ja v a 2s . c o m JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(of.createSession(st), writer); } catch (JAXBException e) { LOG.error("Problem with write configuration: " + e.toString(), e); throw new RuntimeException("Problem with write configuration: " + e.toString(), e); } }
From source file:com.moss.nomad.core.packager.Packager.java
public void write(OutputStream o) throws Exception { JarOutputStream out = new JarOutputStream(o); {/*from w w w . j a v a 2 s . c om*/ ByteArrayOutputStream bao = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(container, bao); byte[] containerIndex = bao.toByteArray(); JarEntry entry = new JarEntry("META-INF/container.xml"); out.putNextEntry(entry); out.write(containerIndex); } final byte[] buffer = new byte[1024 * 10]; //10k buffer for (String path : dependencies.keySet()) { ResolvedDependencyInfo info = dependencies.get(path); JarEntry entry = new JarEntry(path); out.putNextEntry(entry); InputStream in = new FileInputStream(info.file()); for (int numRead = in.read(buffer); numRead != -1; numRead = in.read(buffer)) { out.write(buffer, 0, numRead); } in.close(); } out.close(); }
From source file:hydrograph.ui.engine.util.ConverterUtil.java
/** * Store file into workspace./*from w w w . j a v a 2s. c o m*/ * * @param graph the graph * @param outPutFile the out put file * @param out the out * @throws JAXBException the JAXB exception * @throws CoreException the core exception */ private void storeFileIntoWorkspace(Graph graph, boolean validate, IFile outPutFile, ByteArrayOutputStream out) throws JAXBException, CoreException { JAXBContext jaxbContext = JAXBContext.newInstance(graph.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); out = new ByteArrayOutputStream(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(graph, out); out = ComponentXpath.INSTANCE.addParameters(out); /* * To-do will be removed in future * String updatedXML=escapeXml(out.toString()); out.reset(); try { if(!unknownComponentLists.isEmpty()) out.write(updatedXML.getBytes()); } catch (IOException ioException) { LOGGER.error("Unable to update escape sequene in xml file",ioException); }*/ if (outPutFile.exists()) { outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, null); } else { outPutFile.create(new ByteArrayInputStream(out.toByteArray()), true, null); } }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * create a Json representation for the given <T> instance * //from w ww . j ava 2 s . c o m * @param instance * - the instance to convert to json * @return a Json representation of the given <T> * @throws JAXBException */ public String asJson(T instance) throws JAXBException { Marshaller marshaller = getMarshaller(instance); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); String result = getString(marshaller, instance); return result; }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * create an xml representation for the given <T> instance * /*from w w w . ja v a2 s . co m*/ * @param instance * - the instance to convert to xml * @return a xml representation of the given <T> instance * @throws JAXBException */ @Override public String asXML(T instance) throws JAXBException { Marshaller marshaller = getMarshaller(instance); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml"); if (fragment) { marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); } String result = getString(marshaller, instance); return result; }
From source file:TwitterRetrieval.java
private void Twitter2XML(PostsType posts, PrintWriter out) throws Exception { JAXBContext context = JAXBContext.newInstance("entities"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(posts, out);//from www .java2 s .com }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterOutbound.java
@Override public void receive(GeoEvent geoEvent) { stringBuffer.setLength(0);// www.j a v a2s .c o m GeoEventDefinition definition = geoEvent.getGeoEventDefinition(); System.out.println("Creating Event to marshal..."); Event event = new Event(); for (FieldDefinition fieldDefinition : definition.getFieldDefinitions()) { try { String attributeName = fieldDefinition.getName(); Object value; if ((value = geoEvent.getField(attributeName)) != null) { if (attributeName.equalsIgnoreCase("version")) { event.setVersion((Double) value); } else if (attributeName.equalsIgnoreCase("uid")) { event.setUid(value.toString()); } else if (attributeName.equalsIgnoreCase("type")) { event.setType(value.toString()); } else if (attributeName.equalsIgnoreCase("how")) { event.setHow(value.toString()); } else if (attributeName.equalsIgnoreCase("time")) { event.setTime((Date) value); } else if (attributeName.equalsIgnoreCase("start")) { event.setStart((Date) value); } else if (attributeName.equalsIgnoreCase("stale")) { event.setStale((Date) value); } else if (attributeName.equalsIgnoreCase("access")) { event.setAccess(value.toString()); } else if (attributeName.equalsIgnoreCase("opex")) { event.setOpex(value.toString()); } else if (attributeName.equalsIgnoreCase("qos")) { event.setQos(value.toString()); } else if (attributeName.equalsIgnoreCase("detail")) { event.setDetail(this.unpackDetial(fieldDefinition, geoEvent.getFieldGroup("detail"))); // GETALLFIELDS // CHECK ITS TYPE IF GROUP THEN INSPECT THEM } else if (attributeName.equalsIgnoreCase("point")) { Point p = pointFromJson(value); event.setPoint(pointFromJson(p)); } } } catch (Exception e) { LOG.error(e.getMessage()); } } ///////////////////////// String xmlResult = null; StringBuilder myResult = new StringBuilder(); int content; System.out.println("Event created."); System.out.println("Marshalling Event into XML."); try { JAXBContext contextObj = JAXBContext.newInstance(Event.class); Marshaller marshallerObj = contextObj.createMarshaller(); marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); marshallerObj.marshal(event, os); ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray()); while ((content = bais.read()) != -1) { myResult.append((char) content); } xmlResult = fixEscapeCharacters(myResult.toString()); System.out.println("**** XML RESULTS ***"); System.out.println(xmlResult); //this.byteListener.receive(ByteBuffer.wrap(xmlResult.getBytes()), ""); super.receive(ByteBuffer.wrap(xmlResult.getBytes()), "", geoEvent); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Done"); }
From source file:com.manydesigns.portofino.persistence.Persistence.java
public synchronized void saveXmlModel() throws IOException, JAXBException { //TODO gestire conflitti con modifiche esterne? File tempFile = File.createTempFile(appModelFile.getName(), ""); JAXBContext jc = JAXBContext.newInstance(Model.JAXB_MODEL_PACKAGES); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(model, tempFile);// ww w . j a v a 2 s . c o m ElementsFileUtils.moveFileSafely(tempFile, appModelFile.getAbsolutePath()); lastLiquibaseRunTime = new Date(0); logger.info("Saved xml model to file: {}", appModelFile); }