static void write( @NonNull final OutputStream out, @NonNull final RemotePlatform platform) throws IOException { Parameters.notNull("out", out); //NOI18N Parameters.notNull("platform", platform); //NOI18N final Document doc = XMLUtil.createDocument( ELM_PLATFORM, null, REMOTE_PLATFORM_DTD_ID, REMOTE_PLATFORM_SYSTEM_ID); final Element platformElement = doc.getDocumentElement(); platformElement.setAttribute(ATTR_NAME, platform.getDisplayName()); final Map<String,String> props = platform.getProperties(); final Element propsElement = doc.createElement(ELM_PROPERTIES); writeProperties(props, propsElement, doc); platformElement.appendChild(propsElement); final Map<String,String> sysProps = platform.getSystemProperties(); final Element sysPropsElement = doc.createElement(ELM_SYSPROPERTIES); writeProperties(sysProps, sysPropsElement, doc); platformElement.appendChild(sysPropsElement); XMLUtil.write(doc, out, "UTF8"); }
private void supplementAlvisNLPDocElement(Document doc) throws XPathExpressionException { Element alvisnlpDocElt = XMLUtils.evaluateElement(alvisnlpDocExpression, doc); if (alvisnlpDocElt == null) { alvisnlpDocElt = XMLUtils.createElement(doc, doc, 0, "alvisnlp-doc"); } ensureAttribute(alvisnlpDocElt, "author", ""); ensureAttribute(alvisnlpDocElt, "date", ""); String klass = getModuleClass(); ensureAttribute(alvisnlpDocElt, "target", klass); ensureAttribute(alvisnlpDocElt, "short-target", klass.substring(klass.lastIndexOf('.') + 1)); alvisnlpDocElt.setAttribute("beta", Boolean.toString(beta)); if (useInstead.length > 0) { alvisnlpDocElt.setAttribute("use-instead", useInstead[0].getCanonicalName()); } supplementSynopsisElement(alvisnlpDocElt); supplementModuleDocElement(alvisnlpDocElt); }
/** * @bug 8139584 * Verifies that the resulting XML contains the standalone setting. */ @Test public void testCreateStartDocument_DOMWriter() throws ParserConfigurationException, XMLStreamException { XMLOutputFactory xof = XMLOutputFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true); eventWriter.add(event); eventWriter.flush(); Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15"); Assert.assertEquals(doc.getXmlVersion(), "1.0"); Assert.assertTrue(doc.getXmlStandalone()); }
/** * Add the web uri and context root elements to the Application xml */ @Override protected void updateApplicationXml(Document doc) throws DeployException { Element moduleElement = findElementWithModule(doc); if (moduleElement != null) { doc.getDocumentElement().removeChild(moduleElement); } //create new module moduleElement = doc.createElement("module"); Element javaElement = doc.createElement("java"); javaElement.appendChild(doc.createTextNode(module)); moduleElement.appendChild(javaElement); doc.getDocumentElement().appendChild(moduleElement); }
/** * Read a generated script if it exists, else create a skeleton. * Imports jdk.xml if appropriate. * @param scriptPath e.g. {@link #FILE_SCRIPT_PATH} or {@link #GENERAL_SCRIPT_PATH} */ Document readCustomScript(String scriptPath) throws IOException, SAXException { // XXX if there is TAX support for rewriting XML files, use that here... FileObject script = helper.getProjectDirectory().getFileObject(scriptPath); Document doc; if (script != null) { InputStream is = script.getInputStream(); try { doc = XMLUtil.parse(new InputSource(is), false, true, null, null); } finally { is.close(); } } else { doc = XMLUtil.createDocument("project", /*XXX:"antlib:org.apache.tools.ant"*/null, null, null); // NOI18N Element root = doc.getDocumentElement(); String projname = ProjectUtils.getInformation(project).getDisplayName(); root.setAttribute("name", NbBundle.getMessage(JavaActions.class, "LBL_generated_script_name", projname)); } if (helper.getProjectDirectory().getFileObject(JdkConfiguration.JDK_XML) != null) { JdkConfiguration.insertJdkXmlImport(doc); } return doc; }
public static void saveUserDefinedProperties() throws XMLException { Document doc; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException var4) { throw new XMLException("Failed to create document: " + var4, var4); } Element root = doc.createElement("drivers"); doc.appendChild(root); Iterator var2 = getJDBCProperties().iterator(); while(var2.hasNext()) { JDBCProperties props = (JDBCProperties)var2.next(); if(props.isUserDefined()) { root.appendChild(props.getXML(doc)); } } XMLTools.stream(doc, getUserJDBCPropertiesFile(), StandardCharsets.UTF_8); }
/** * Billing test for price model with stepped price. * * @throws Exception */ private void testBillingWithRolesForUserAssignment(int numUser, BigDecimal expectedPrice) throws Exception { final int testMonth = Calendar.APRIL; final int testDay = 1; final int testYear = 2010; final long billingTime = getTimeInMillisForBilling(testYear, testMonth, testDay); long subscriptionCreationTime = getTimeInMillisForBilling(testYear, testMonth - 2, testDay); long subscriptionActivationTime = getTimeInMillisForBilling(testYear, testMonth - 2, testDay); int userNumber = numUser; initDataPriceModel(userNumber, subscriptionCreationTime, subscriptionActivationTime); runTX(new Callable<Void>() { @Override public Void call() throws Exception { billingService.startBillingRun(billingTime); return null; } }); Document doc = getBillingDocument(); String costs = XMLConverter.getNodeTextContentByXPath(doc, "/BillingDetails/OverallCosts/@grossAmount"); checkEquals(expectedPrice.toPlainString(), costs); }
public void testWithMapOfLists() throws Exception { List<ClassD> classDList = newListWith(new ClassD("classD-1"), new ClassD("classD-2")); Map<String, List<ClassD>> map = new HashMap(); map.put("one", classDList); this.convertToXmlWith(map); File xmlLog = JrpipLogGenerator.findLogFileByExtension(JRPIP_LOG_BIN_DIR, ".xml"); Assert.assertTrue(xmlLog.exists()); Document doc = this.createXmlDocument(xmlLog); NodeList nList1 = doc.getElementsByTagName("key"); Assert.assertEquals(1, nList1.getLength()); NodeList nList2 = doc.getElementsByTagName("ClassD"); Assert.assertEquals(2, nList2.getLength()); NodeList nList3 = doc.getElementsByTagName("String"); Assert.assertEquals(1, nList3.getLength()); }
/** * Merges list of XML files presented by fileList into a single * XML Document with a given root. * * @param fileList list of File objects * @param rootElementName - name of a root element * * @return Document */ public static Document merge(final List fileList, final String rootElementName) throws ParserConfigurationException, SAXException, IOException { final Document mergedDocument = createDomDocument(); final Element element = mergedDocument.createElement(rootElementName); mergedDocument.appendChild(element); for (final Iterator i = fileList.iterator(); i.hasNext();) { final File file = (File)i.next(); if (file.isDirectory()) continue; final Document documentToMerge = parseDom(file, false); final NodeList list = documentToMerge.getElementsByTagName("*"); final Element rootElement = (Element)list.item(0); final Node duplicate = mergedDocument.importNode(rootElement, true); mergedDocument.getDocumentElement().appendChild(duplicate); } return mergedDocument; }
private void readColumnValue(Document doc, Map<String, String> xmlFieldXPaths, String columnName, Object value, ReportResultData reportData, int index, Element node) throws XPathExpressionException { if ("RESULTXML".equalsIgnoreCase(columnName) || "PROCESSINGRESULT".equalsIgnoreCase(columnName)) { Document columnValueAsDoc = parseXML((String) reportData .getColumnValue().get(index)); if (xmlFieldXPaths.containsKey(columnName.toLowerCase())) { String xpathEvaluationResult = XMLConverter .getNodeTextContentByXPath(columnValueAsDoc, xmlFieldXPaths.get(columnName)); // don't store null values but empty strings instead, to ensure // proper display on client side if (xpathEvaluationResult == null) { xpathEvaluationResult = ""; } node.appendChild(doc.createTextNode(xpathEvaluationResult)); } else { appendXMLStructureToNode(node, columnValueAsDoc); } } else { node.appendChild(doc.createTextNode(value.toString())); } }
/** * Constructor KeyValue * * @param doc * @param pk */ public KeyValue(Document doc, PublicKey pk) { super(doc); XMLUtils.addReturnToElement(this.constructionElement); if (pk instanceof java.security.interfaces.DSAPublicKey) { DSAKeyValue dsa = new DSAKeyValue(this.doc, pk); this.constructionElement.appendChild(dsa.getElement()); XMLUtils.addReturnToElement(this.constructionElement); } else if (pk instanceof java.security.interfaces.RSAPublicKey) { RSAKeyValue rsa = new RSAKeyValue(this.doc, pk); this.constructionElement.appendChild(rsa.getElement()); XMLUtils.addReturnToElement(this.constructionElement); } }
private Collection<PersistenceUnitInfoImpl> unitsFrom( final JavaArchive archive, final ClasspathResource xml ) { try { final Document doc = BUILDER.parse(new ByteArrayInputStream(xml.getBytes())); final Element root = doc.getDocumentElement(); final NodeList unitNodes = (NodeList) xpath().evaluate( "//persistence/persistence-unit", root, NODESET ); final Collection<PersistenceUnitInfoImpl> ret = new HashSet<>(); for (int i = 0; i < unitNodes.getLength(); i++) { ret.add(createUnitInfo(archive, (Element) unitNodes.item(i))); } return ret; } catch (final XPathExpressionException | SAXException | IOException e) { throw new TestEEfiException("Failed to read persistence.xml", e); } }
/** * * Convert XML string to {@link Document} * * @param xmlString * @return {@link Document} */ public static Document convertStringToDocument(String xmlString) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { factory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true); builder = factory.newDocumentBuilder(); Document doc = builder.parse( new InputSource( new StringReader( xmlString ) ) ); return doc; } catch (ParserConfigurationException| SAXException| IOException e) { logger.debug("Unable to convert string to Document",e); } return null; }
@Override public javax.swing.text.Document loadSwingDocument(InputStream in) throws IOException, BadLocationException { javax.swing.text.Document sd = new PlainDocument(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { String line = null; while ((line = br.readLine()) != null) { sd.insertString(sd.getLength(), line+System.getProperty("line.separator"), null); // NOI18N } } finally { br.close(); } return sd; }
private void validateProcess(InputStream inputStream) { StringBuffer errorInfo=new StringBuffer(); try { Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream); List<String> errors=new ArrayList<String>(); List<String> nodeNames=new ArrayList<String>(); Element element=document.getDocumentElement(); if(processValidator.support(element)){ processValidator.validate(element, errors, nodeNames); if(errors.size()>0){ for(int i=0;i<errors.size();i++){ errorInfo.append((i+1)+"."+errors.get(i)+"\r\r"); } } }else{ errorInfo.append("当前XML文件不是一个合法的UFLO流程模版文件"); } } catch (Exception e) { throw new RuntimeException(e); } String msg=errorInfo.toString(); if(StringUtils.isNotEmpty(msg)){ throw new ProcessValidateException(msg); } }
/** * Constructor RSAKeyValue * * @param doc * @param key * @throws IllegalArgumentException */ public RSAKeyValue(Document doc, Key key) throws IllegalArgumentException { super(doc); XMLUtils.addReturnToElement(this.constructionElement); if (key instanceof java.security.interfaces.RSAPublicKey ) { this.addBigIntegerElement( ((RSAPublicKey) key).getModulus(), Constants._TAG_MODULUS ); this.addBigIntegerElement( ((RSAPublicKey) key).getPublicExponent(), Constants._TAG_EXPONENT ); } else { Object exArgs[] = { Constants._TAG_RSAKEYVALUE, key.getClass().getName() }; throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs)); } }
/**@param{Object} Address- The physical address of a location * This method returns Geocode coordinates of the Address object.Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, * Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739).Please give all the physical Address values * for a precise coordinate. setting none of the values will give a null value for the Latitude and Longitude. */ public static GeoCode getCoordinates(Address address) throws Exception { GeoCode geo= new GeoCode(); String physicalAddress = (address.getAddress1() == null ? "" : address.getAddress1() + ",") + (address.getAddress2() == null ? "" : address.getAddress2() + ",") + (address.getCityName() == null ? "" : address.getCityName() + ",") + (address.getState() == null ? "" : address.getState() + "-") + (address.getZip() == null ? "" : address.getZip() + ",") + (address.getCountry() == null ? "" : address.getCountry()); String api = GMAPADDRESS + URLEncoder.encode(physicalAddress, "UTF-8") + SENSOR; URL url = new URL(api); HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection(); httpConnection.connect(); int responseCode = httpConnection.getResponseCode(); if(responseCode == 200) { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(httpConnection.getInputStream()); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile(STATUS); String status = (String)expr.evaluate(document, XPathConstants.STRING); if(status.equals("OK")) { expr = xpath.compile(LATITUDE); String latitude = (String)expr.evaluate(document, XPathConstants.STRING); expr = xpath.compile(LONGITUDE); String longitude = (String)expr.evaluate(document, XPathConstants.STRING); geo.setLatitude(latitude); geo.setLongitude(longitude); } } else { throw new Exception("Fail to Convert to Geocode"); } return geo; }
@Test public void shouldCreateCategoryWithTextValue() throws Exception { final String categoryName = CATEGORY_TEXT; rss.getChannel().setCategory(Collections.singletonList(new Category().setTextValue(categoryName))); final Document document = XmlUtils.getDocument(rss); final XpathEngine engine = XmlUtils.getXpathEngine(); NodeList matchingNodes = engine.getMatchingNodes(String.format("/rss/channel/category", categoryName), document); assertEquals("Could not category element", 1, matchingNodes.getLength()); assertEquals("Category element had unexpected text", categoryName, matchingNodes.item(0).getTextContent()); }
protected Element ExportCustom(Document root) { Element eDiv = root.createElement("Divide") ; if (m_bIsRounded) { eDiv.setAttribute("Rounded", "true"); } Element eWhat = root.createElement("Divide") ; eDiv.appendChild(eWhat); m_DivideWhat.ExportTo(eWhat, root); Element eBy = root.createElement("By") ; eDiv.appendChild(eBy) ; m_DivideBy.ExportTo(eBy, root) ; if (m_Result != null) { Element eTo = root.createElement("To") ; eDiv.appendChild(eTo) ; m_Result.ExportTo(eTo, root) ; } if (m_Remainder != null) { Element eRem = root.createElement("Remainder") ; eDiv.appendChild(eRem) ; m_Remainder.ExportTo(eRem, root) ; } return eDiv; }
public static Document addJob(CacheManager cacheManager, DatabaseObject requestedObject, Requester requester, Context context) throws EngineException { Engine.logJobManager.debug("Adding job #" + context.contextID); Job job = new Job(cacheManager, requestedObject, requester, context); jobs.put(context.contextID, job); job.start(); return JobManager.getJobStatus(context.contextID); }
/** * Constructor SignatureAlgorithm * * @param doc * @param algorithmURI * @throws XMLSecurityException */ public SignatureAlgorithm(Document doc, String algorithmURI) throws XMLSecurityException { super(doc, algorithmURI); this.algorithmURI = algorithmURI; signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI); signatureAlgorithm.engineGetContextFromElement(this.constructionElement); }
/** * Implemented to replace the content handler currently in use by a * NodeBuilder. * * @param namespaceURI * the namespace URI of the matching element, or an empty string * if the parser is not namespace aware or the element has no * namespace * @param name * the local name if the parser is namespace aware, or just the * element name otherwise * @param attributes * The attribute list of this element * @throws Exception * indicates a JAXP configuration problem */ @Override public void begin(String namespaceURI, String name, Attributes attributes) throws Exception { XMLReader xmlReader = getDigester().getXMLReader(); Document doc = documentBuilder.newDocument(); NodeBuilder builder = null; if (nodeType == Node.ELEMENT_NODE) { Element element = null; if (getDigester().getNamespaceAware()) { element = doc.createElementNS(namespaceURI, name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttributeNS(attributes.getURI(i), attributes.getLocalName(i), attributes.getValue(i)); } } else { element = doc.createElement(name); for (int i = 0; i < attributes.getLength(); i++) { element.setAttribute(attributes.getQName(i), attributes.getValue(i)); } } builder = new NodeBuilder(doc, element); } else { builder = new NodeBuilder(doc, doc.createDocumentFragment()); } xmlReader.setContentHandler(builder); }
/** * Constructor KeyValue * * @param doc * @param unknownKeyValue */ public KeyValue(Document doc, Element unknownKeyValue) { super(doc); XMLUtils.addReturnToElement(this.constructionElement); this.constructionElement.appendChild(unknownKeyValue); XMLUtils.addReturnToElement(this.constructionElement); }
public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); }
@Test public void billingPerUnitWeekBug10235_with_free_period() throws Exception { // given subscription data for scenario testSetup.createWeekScenarioBug10235_with_free_period(); // when billing run performed performBillingRun(0, "2013-06-06 07:00:00"); // then VOSubscriptionDetails voSubscriptionDetails = getSubscriptionDetails( "BUG10235_FREE_PERIOD_UNIT_WEEK", 0); Document billingResult = loadBillingResult( voSubscriptionDetails.getKey(), DateTimeHandling.calculateMillis("2013-05-04 00:00:00"), DateTimeHandling.calculateMillis("2013-06-04 00:00:00")); BillingResultEvaluator eva = new BillingResultEvaluator(billingResult); Node priceModel = BillingXMLNodeSearch.getPriceModelNode(billingResult, voSubscriptionDetails.getPriceModel().getKey()); eva.assertOneTimeFee(priceModel, "25.00"); eva.assertOverallCosts("1230.00", "EUR", "1230.00"); voSubscriptionDetails = getSubscriptionDetails( "BUG10235_FREE_PERIOD_UNIT_WEEK", 0); assertNull(getEvaluator(voSubscriptionDetails.getKey(), "2013-04-04 00:00:00", "2013-05-04 00:00:00")); }
private static void saveTemplate(Document doc, String templateDir) throws EngineException { try { XMLUtils.saveXml(doc, templateDir); } catch (Exception e) { throw new EngineException("Unable to create template file \""+templateDir+"\"", e); } }
/** * Load recursive. * * @param pModule the module * @throws Exception in case a problem occurred */ private void loadRecursive(String pModule) throws Exception { if (!mDocuments.containsKey(pModule)) { mDocuments.put(pModule, null); mInheritance.put(pModule, new ArrayList<String>()); Document tDoc = loadCwfModuleDocument(pModule); mDocuments.put(pModule, tDoc); checkVersion(tDoc, pModule); for (String tInherits : getInheritedModules(tDoc)) { mInheritance.get(pModule).add(tInherits); loadRecursive(tInherits); } } }
/** * Creates a configuration document for a TiledImageLayer described by the specified params. The returned document * may be used as a construction parameter to {@link gov.nasa.worldwind.layers.BasicTiledImageLayer}. * * @param params parameters describing the TiledImageLayer. * * @return a configuration document for the TiledImageLayer. */ public static Document createTiledImageLayerConfigDocument(AVList params) { Document doc = WWXML.createDocumentBuilder(true).newDocument(); Element root = WWXML.setDocumentElement(doc, "Layer"); WWXML.setIntegerAttribute(root, "version", 1); WWXML.setTextAttribute(root, "layerType", "TiledImageLayer"); createTiledImageLayerConfigElements(params, root); return doc; }
public static Object getBean(String path, String args) { try { //创建文档对象 DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc; doc = builder.parse(new File(ToolDirFile.getClassesPath(XMLUtil.class) + path)); NodeList nl = null; Node classNode = null; String cName = null; nl = doc.getElementsByTagName("className"); if (args.equals("image")) { //获取第一个包含类名的节点,即扩充抽象类 classNode = nl.item(0).getFirstChild(); } else if (args.equals("os")) { //获取第二个包含类名的节点,即具体实现类 classNode = nl.item(1).getFirstChild(); } cName = classNode.getNodeValue(); //通过类名生成实例对象并将其返回 Class c = Class.forName(cName); Object obj = c.newInstance(); return obj; } catch (Exception e) { e.printStackTrace(); return null; } }
/** {@inheritDoc} */ public Element marshall(XMLObject xmlObject) throws MarshallingException { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); return marshall(xmlObject, document); } catch (ParserConfigurationException e) { throw new MarshallingException("Unable to create Document to place marshalled elements in", e); } }
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { InputStream inputStream = new FileInputStream("e://a.txt"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(inputStream); String type = Msg.readMsgType(document); System.out.println(type); Msg msg = new Msg(document); System.out.println(msg.getContent()); }
private SOAPElement convertToSoapElement(Element element) throws SOAPException { if (element instanceof SOAPElement) { return (SOAPElement) element; } SOAPElement copy = createElement( element.getLocalName(), element.getPrefix(), element.getNamespaceURI()); Document ownerDoc = copy.getOwnerDocument(); NamedNodeMap attrMap = element.getAttributes(); for (int i=0; i < attrMap.getLength(); i++) { Attr nextAttr = (Attr)attrMap.item(i); Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true); copy.setAttributeNodeNS(importedAttr); } NodeList nl = element.getChildNodes(); for (int i=0; i < nl.getLength(); i++) { org.w3c.dom.Node next = nl.item(i); org.w3c.dom.Node imported = ownerDoc.importNode(next, true); copy.appendChild(imported); } return copy; }
@Test public void testAsString() throws Exception { Document document = documentFrom(DOCUMENT); XPath xpath = xpath(); assertEquals("Boo", asString("Foo/Title", document, xpath)); assertEquals("", XpathUtils.asString("Foo/Empty", document, xpath)); assertEquals("Bar", XpathUtils.asString("Foo/Count/@Foo", document, xpath)); }
public static Document parseXmlFile(File file) { //create the document object Document dom = null; try { /* Get DOM representation of the XML file */ dom = db.parse(file); db.reset(); } catch (SAXException | IOException exc) { exc.printStackTrace(); } return dom; }
/** add the agent in the list of available agent for mind inspection */ public synchronized void registerAg(Agent ag) { String agName = ag.getTS().getUserAgArch().getAgName(); if (!agName.equals("no-named")) { registeredAgents.put(agName, ag); histories.put(agName, new ArrayList<Document>()); // just for the agent name to appear in the list of agents } }
protected ResellerShareResultEvaluator newResellerShareResultEvaluator( long resellerKey, final String periodStart, final String periodEnd) throws Exception { Document sharesResult = loadSharesResult(resellerKey, periodStart, periodEnd, BillingSharesResultType.RESELLER); return new ResellerShareResultEvaluator(sharesResult); }
/** * Test the default functionality of setValidating method. The * XML file has a DTD which has namespaces defined. The parser takes care to * check if the namespaces using elements and defined attributes are there * or not. * @throws Exception If any errors occur. */ @Test public void testCheckDocumentBuilderFactory06() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true); DocumentBuilder db = dbf.newDocumentBuilder(); MyErrorHandler eh = MyErrorHandler.newInstance(); db.setErrorHandler(eh); Document doc = db.parse(new File(XML_DIR, "DocumentBuilderFactory04.xml")); assertTrue(doc instanceof Document); assertFalse(eh.isErrorOccured()); }
/** * Makes a new document adopt a node from a different document, and correctly reassign namespace * and prefix * @param document the new document * @param node the node to adopt. * @return the adopted node. */ static Node adoptNode(Document document, Node node) { Node newNode = document.adoptNode(node); updateNamespace(newNode, document); return newNode; }
@Override public void initialize(URL location, ResourceBundle resources) { addEventHandlers(); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(FEFEditor.class.getResourceAsStream("data/xml/Dialogue.xml")); doc.getDocumentElement().normalize(); NodeList nList = doc.getDocumentElement().getElementsByTagName("Types").item(0).getChildNodes(); for (int x = 0; x < nList.getLength(); x++) { if (nList.item(x).getNodeType() == Node.ELEMENT_NODE) { Node node = nList.item(x); dialogueList.getItems().add(node.getAttributes().getNamedItem("name").getNodeValue()); prefixes.add(node.getAttributes().getNamedItem("prefix").getNodeValue()); suffixes.add(node.getAttributes().getNamedItem("suffix").getNodeValue()); } } byte[] bytes = CompressionUtils.decompress(FileData.getInstance().getWorkingFile()); String[] lines = CompressionUtils.extractMessageArchive(bytes); List<String> list = new ArrayList<>(); list.addAll(Arrays.asList(lines)); fileMap.put(FileData.getInstance().getWorkingFile().getAbsolutePath(), list); } catch (Exception ex) { ex.printStackTrace(); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Decompression Error"); alert.setHeaderText("Unable to decompress file."); alert.setContentText("Dialogue Editor was unable to properly decompress one of your files."); alert.showAndWait(); } }
@Test public void billingRataWeekBug10235_with_free_period() throws Exception { // given subscription data for scenario testSetup.createWeekScenarioBug10235_with_free_period_Rata(); // when billing run performed performBillingRun(0, "2013-06-06 07:00:00"); // then VOSubscriptionDetails voSubscriptionDetails = getSubscriptionDetails( "BUG10235_FREE_PERIOD_RATA_WEEK", 0); Document billingResult = loadBillingResult( voSubscriptionDetails.getKey(), DateTimeHandling.calculateMillis("2013-05-04 00:00:00"), DateTimeHandling.calculateMillis("2013-06-04 00:00:00")); BillingResultEvaluator eva = new BillingResultEvaluator(billingResult); Node priceModel = BillingXMLNodeSearch.getPriceModelNode(billingResult, voSubscriptionDetails.getPriceModel().getKey()); eva.assertOneTimeFee(priceModel, "25.00"); Node roleCosts = BillingXMLNodeSearch.getRoleCostsNode(priceModel); eva.assertRoleCost(roleCosts, "ADMIN", "6.00", 4.386904761904762, "26.32"); eva.assertUserAssignmentCostsByUser(priceModel, "GreenPeaceCustomerUser1", 4.386904761904762); eva.assertOverallCosts("1082.25", "EUR", "1082.25"); voSubscriptionDetails = getSubscriptionDetails( "BUG10235_FREE_PERIOD_RATA_WEEK", 0); assertNull(getEvaluator(voSubscriptionDetails.getKey(), "2013-04-04 00:00:00", "2013-05-04 00:00:00")); }