List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:com.aionemu.packetsamurai.utils.collector.data.npcskills.NpcSkillsTool.java
public static void save() { ObjectFactory objFactory = new ObjectFactory(); NpcSkillTemplates collection = objFactory.createNpcSkillTemplates(); List<NpcSkillList> templateList = collection.getNpcskills(); templateList.addAll(skillsByNpcId.values()); Collections.sort(templateList); NpcSkillTemplate total = new NpcSkillTemplate(); total.setSkillid(0);//w w w . j av a 2 s. c o m List<NpcSkillList> toRemove = new ArrayList<NpcSkillList>(); for (NpcSkillList skillList : templateList) { HashMap<IntRange, Integer> useCounts = new HashMap<IntRange, Integer>(); HashMap<NpcSkillTemplate, Integer> skillCounts = new HashMap<NpcSkillTemplate, Integer>(); NpcSkillTemplate totalAttacks = null; int index = 0; if (skillList.getNpcskill().contains(total)) { totalAttacks = skillList.getNpcskill().get(index); index = skillList.getNpcskill().indexOf(total); skillList.getNpcskill().remove(index); } int useTotal = 0; int skillUseTotal = 0; for (NpcSkillTemplate template : skillList.getNpcskill()) skillUseTotal += template.getStats().useCount; if (totalAttacks != null) { useTotal = totalAttacks.getStats().useCount; if (skillUseTotal > useTotal) useTotal = skillUseTotal; } else { useTotal = skillUseTotal; } if (skillList.getNpcskill().size() == 0) { toRemove.add(skillList); continue; } else if (useTotal == 0) { // old data from XML continue; } for (NpcSkillTemplate template : skillList.getNpcskill()) { if (useTotal < MAX_HITS_PER_NPC) { if (template.getStats().maxHp > 90) template.setMaxhp(100); else if (template.getMaxhp() == null || template.getMaxhp() < template.getStats().maxHp) template.setMaxhp(template.getStats().maxHp); if (template.getStats().minHp < 10) template.setMinhp(0); else if (template.getMinhp() == null || template.getMinhp() > template.getStats().minHp) template.setMinhp(template.getStats().minHp); } else { IntRange hpRange = new IntRange(template.getStats().minHp, template.getStats().maxHp); if (useCounts.containsKey(hpRange)) { int oldCounts = useCounts.get(hpRange); useCounts.put(hpRange, oldCounts + template.getStats().useCount); } else useCounts.put(hpRange, template.getStats().useCount); skillCounts.put(template, template.getStats().useCount); } if (useTotal >= MAX_HITS_PER_NPC) template.setProbability(Math.round((float) template.getStats().useCount * 100 / useTotal)); else { template.setProbability(25); } } } templateList.removeAll(toRemove); try { JAXBContext jaxbContext = JAXBContext .newInstance("com.aionemu.packetsamurai.utils.collector.data.npcskills"); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(collection, new FileOutputStream("data/npc_skills/npc_skills.xml")); } catch (PropertyException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } PacketSamurai.getUserInterface().log("Skills [Npcs] - Saved : " + templateList.size() + " Npc Skills!"); }
From source file:Main.java
public static void marshal(JAXBContext context, Object object, Writer writer, Map<String, Object> properties) throws JAXBException { if (object == null) { return;/*from w w w. java 2 s. c o m*/ } if (writer == null) { return; } if (context == null) { context = JAXBContext.newInstance(object.getClass()); } Marshaller marshaller = context.createMarshaller(); if (properties != null) { Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Object> entry = it.next(); marshaller.setProperty(entry.getKey(), entry.getValue()); } } marshaller.marshal(object, writer); }
From source file:edu.harvard.lib.lcloud.SolrItem.java
protected static void marshalingExample(Item item) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(Item.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(item, System.out); }
From source file:com.vangent.hieos.services.xds.bridge.utils.JUnitHelper.java
/** * Method description//from w w w. j a v a 2 s . c o m * * * * * @param file * @param count * @param documentIds * @return * * @throws Exception */ public static OMElement createOMRequest(String file, int count, String[] documentIds) throws Exception { ObjectFactory factory = new ObjectFactory(); SubmitDocumentRequest sdr = factory.createSubmitDocumentRequest(); IdType pid = factory.createIdType(); pid.setRoot("1.3.6.1.4.1.21367.2005.3.7.6fa11e467880478"); sdr.setPatientId(pid); ClassLoader classLoader = JUnitHelper.class.getClassLoader(); DocumentsType documents = factory.createDocumentsType(); for (int i = 0; i < count; ++i) { DocumentType document = factory.createDocumentType(); if ((documentIds != null) && (documentIds.length > i)) { document.setId(documentIds[i]); } CodeType type = factory.createCodeType(); type.setCode("51855-5"); type.setCodeSystem("2.16.840.1.113883.6.1"); document.setType(type); ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = classLoader.getResourceAsStream(file); assertNotNull(is); IOUtils.copy(is, bos); document.setContent(bos.toByteArray()); documents.getDocument().add(document); } sdr.setDocuments(documents); QName qname = new QName(URIConstants.XDSBRIDGE_URI, "SubmitDocumentRequest"); JAXBContext jc = JAXBContext.newInstance(SubmitDocumentRequest.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); JAXBElement element = new JAXBElement(qname, sdr.getClass(), sdr); StringWriter sw = new StringWriter(); marshaller.marshal(element, sw); String xml = sw.toString(); logger.debug(xml); OMElement result = AXIOMUtil.stringToOM(OMAbstractFactory.getOMFactory(), xml); List<OMElement> list = XPathHelper.selectNodes(result, "./ns:Documents/ns:Document/ns:Content", URIConstants.XDSBRIDGE_URI); for (OMElement contentNode : list) { OMText binaryNode = (OMText) contentNode.getFirstOMChild(); if (binaryNode != null) { binaryNode.setOptimize(true); } } return result; }
From source file:com.evolveum.midpoint.testing.model.client.sample.RunScript.java
private static String marshalObject(Object object) throws JAXBException, FileNotFoundException { JAXBContext jc = getJaxbContext(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); marshaller.marshal(object, sw);//from ww w . j a v a2 s . c o m return sw.toString(); }
From source file:edu.lternet.pasta.common.EmlUtility.java
/** * Creates and returns an EML 2.1.0 {@code <access} element string that * corresponds to the provided JAXB object. * * @param accessType//from w w w .jav a 2s.c o m * the JAXB object to be represented as a string. * @return an EML 2.1.0 {@code <access} element string that corresponds to * the provided JAXB object. */ public static String toString(AccessType accessType) { try { ObjectFactory factory = new ObjectFactory(); JAXBElement<AccessType> jaxb = factory.createAccess(accessType); StringWriter writer = new StringWriter(); String packageName = AccessType.class.getPackage().getName(); JAXBContext jc = JAXBContext.newInstance(packageName); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(jaxb, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e); } }
From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java
@SuppressWarnings("all") private static void testGetUserLicenseQuery() throws Exception { GetUserQueryInputDTO input = new GetUserQueryInputDTO(); input.setPresentationType("images"); input.setAttributes(createUserObjAttributeDTO()); JAXBContext context = JAXBContext.newInstance(GetUserQueryInputDTO.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(input, outputStream);/* w w w. j a va2s.co m*/ // serialize to XML String inputXML = outputStream.toString(); System.out.println(inputXML); ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client .resource(UriBuilder.fromUri("http://localhost:8080/licensemodule/services/").build()); // Call with XML String output = service.path("getUserLicenseQuery").type(MediaType.TEXT_XML).accept(MediaType.TEXT_XML) .entity(inputXML).post(String.class); System.out.println("query:" + output); }
From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandler.java
static Marshaller createMarshaller(AttachmentMarshaller attachmentMarshaller) throws Exception { Marshaller marshaller = JAXB_CTX.createMarshaller(); marshaller.setAttachmentMarshaller(attachmentMarshaller); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); return marshaller; }
From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java
@SuppressWarnings("all") private static void testGetUsersGroups() throws Exception { GetUserGroupsInputDTO input = new GetUserGroupsInputDTO(); input.setAttributes(createUserObjAttributeDTO()); input.setLocale("da"); JAXBContext context = JAXBContext.newInstance(GetUserGroupsInputDTO.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(input, outputStream);/*from w w w. ja v a2 s. c o m*/ // serialize to XML String inputXML = outputStream.toString(); System.out.println("input xml:\n" + inputXML); ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client .resource(UriBuilder.fromUri("http://localhost:8080/licensemodule/services/").build()); // Call with XML //GetUsersLicensesOutputDTO output = service.path("getUserLicenses").type(MediaType.TEXT_XML).accept(MediaType.TEXT_XML).entity(inputXML).post(GetUsersLicensesOutputDTO.class); // Call with @XmlRootElement GetUserGroupsOutputDTO output = service.path("getUserGroups").type(MediaType.TEXT_XML) .accept(MediaType.TEXT_XML).entity(input).post(GetUserGroupsOutputDTO.class); context = JAXBContext.newInstance(GetUserGroupsOutputDTO.class); outputStream = new ByteArrayOutputStream(); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(output, outputStream); // serialize to XML String outputXML = outputStream.toString(); System.out.println(outputXML); System.out.println("output, groups:" + output.getGroups()); }
From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java
@SuppressWarnings("all") private static void testGetUsersLicenses() throws Exception { // GetUserLicensesOutputDTO getUserLicenses GetUsersLicensesInputDTO input = new GetUsersLicensesInputDTO(); input.setAttributes(createUserObjAttributeDTO()); input.setLocale("da"); JAXBContext context = JAXBContext.newInstance(GetUsersLicensesInputDTO.class); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(input, outputStream);//from ww w .j a v a 2s. c om // serialize to XML String inputXML = outputStream.toString(); System.out.println("input xml:\n" + inputXML); ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client .resource(UriBuilder.fromUri("http://localhost:8080/licensemodule/services/").build()); // Call with XML //GetUsersLicensesOutputDTO output = service.path("getUserLicenses").type(MediaType.TEXT_XML).accept(MediaType.TEXT_XML).entity(inputXML).post(GetUsersLicensesOutputDTO.class); // Call with @XmlRootElement GetUsersLicensesOutputDTO output = service.path("getUserLicenses").type(MediaType.TEXT_XML) .accept(MediaType.TEXT_XML).entity(input).post(GetUsersLicensesOutputDTO.class); context = JAXBContext.newInstance(GetUsersLicensesOutputDTO.class); outputStream = new ByteArrayOutputStream(); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(output, outputStream); // serialize to XML String outputXML = outputStream.toString(); System.out.println(outputXML); System.out.println("output, licensenames:" + output.getLicenses()); }