/** * Gets the itemRecord attribute of the GetRecordResponse class. The * itemRecord is the ADN item-level record contained in the GetRecord Service * Response. * *@return The itemRecord value *@exception WebServiceClientException Description of the Exception */ public Document getItemRecord() throws WebServiceClientException { if (itemRecord == null) { // now extract the itemRecord element String rootXPath = "/DDSWebService/GetRecord/record/metadata/itemRecord"; try { Node rootNode = document.selectSingleNode(rootXPath); if (rootNode == null) { String msg = "getItemRecord() failed to find itemRecord"; prtln(msg); throw new WebServiceClientException(msg); // prtln(Dom4jUtils.prettyPrint(document)); } // clone the root and create a new document with it Element rootClone = (Element) rootNode.clone(); itemRecord = DocumentFactory.getInstance().createDocument(rootClone); } catch (Throwable e) { throw new WebServiceClientException(e.getMessage()); } } return itemRecord; }
/** * Initialize Renderer attributes * * @param xpath The jsp-encoded xpath to the element to be rendered. * @param parent The {@link SchemaNode} which wraps the schema element (which may represent an Element * Attribute) being rendered * @param rhelper Data structure containing global information required by individual Renderer instances */ protected void init(String xpath, Element parent, RendererHelper rhelper) { this.xpath = xpath; this.parent = parent; this.rhelper = rhelper; this.sh = rhelper.getSchemaHelper(); this.root = rhelper.getRoot(); this.formBeanName = rhelper.getFormBeanName(); df = DocumentFactory.getInstance(); normalizedXPath = RendererHelper.normalizeXPath(xpath); schemaNode = sh.getSchemaNode(normalizedXPath); // guard against infinite loops // prtln("*** State.counter is " + rhelper.counter + ") ***"); int maxCount = 2000; // 2000 if (++rhelper.counter > maxCount) { System.out.println("\n*** Renderer forcing Sytem Exit (counter is " + rhelper.counter + ") ***"); System.exit(rhelper.counter); } }
protected Element createElement(String newName, Element element, String elementName) { Element newElement = null; String targetName = newName; if (element != null) { if ((newName == null) || ("".equals(newName))) { targetName = element.getName(); } newElement = element.createCopy(); newElement.addAttribute("name", targetName); } else { if ((elementName != null) && (!"".equals(elementName))) { DocumentFactory factory = DocumentFactory.getInstance(); newElement = factory.createElement(elementName); newElement.addAttribute("name", targetName); } } return newElement; }
public XMLBuilder(String rootNode,Map<String, String> uris) throws XMLException { try { DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); dom4JDocument = factory.createDocument(); root = dom4JDocument.addElement( rootNode ); Iterator<?> iterator = uris.entrySet().iterator(); while (iterator.hasNext()) { @SuppressWarnings("rawtypes") Map.Entry pairs = (Map.Entry)iterator.next(); root.add(Namespace.get((String)pairs.getKey(), (String) pairs.getValue())); } } catch (Exception e) { throw new XMLException(e.getMessage()); } }
public XMLBuilder(String rootNode,Map<String, String> uris,String encoding) throws XMLException { try { DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); dom4JDocument = factory.createDocument(); if(encoding!=null) dom4JDocument.setXMLEncoding(encoding); root = dom4JDocument.addElement( rootNode ); Iterator<?> iterator = uris.entrySet().iterator(); while (iterator.hasNext()) { @SuppressWarnings("rawtypes") Map.Entry pairs = (Map.Entry)iterator.next(); root.add(Namespace.get((String)pairs.getKey(), (String) pairs.getValue())); } } catch (Exception e) { throw new XMLException(e.getMessage()); } }
public void testEscapeXML() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputFormat format = new OutputFormat(null, false, "ISO-8859-2"); format.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(os, format); Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("root"); root.setText("bla &#c bla"); writer.write(document); String result = os.toString(); Document doc2 = DocumentHelper.parseText(result); doc2.normalize(); }
private Document readDocument() throws AccountPersistException { File dataFile = new File(file); if (!dataFile.exists()) { dataFile.getParentFile().mkdirs(); Document doc = DocumentFactory.getInstance().createDocument(); Element rootEle = doc.addElement(ELEMENT_ROOT); rootEle.addElement(ELEMENT_ACCOUNTS); writeDocument(doc); } try { return reader.read(new File(file)); } catch (DocumentException e) { throw new AccountPersistException("Unable to read persist data xml", e); } }
static String generateDevRegMessageStanza() { DevReg reg = new DevReg(); reg.setDevId("%%ts_user_server:get_unique_id%%"); // let tsung generate a unique id //reg.setDevId(devid); reg.setOsType(OSType.ANDROID.name()); reg.setDisplayName("Loadtester"); reg.setOsVersion("4.4"); reg.setApiKey(genSettings.apiKey); //send an IQ request with device registration DocumentFactory factory = new DocumentFactory(); final Element element = factory.createElement(Constants.MMX_DEV_REG, Constants.MMX_NS_DEV); element.addAttribute(Constants.MMX_ATTR_COMMAND, Constants.DeviceCommand.REGISTER.name()); element.setText(reg.toJson()); IQ devRegIq = new IQ() { @Override public CharSequence getChildElementXML() { return element.asXML(); } }; devRegIq.setType(IQ.Type.SET); devRegIq.setFrom("%%_username%%"); return devRegIq.toXML().toString(); }
public Element createResultElement() { final Element set; set = DocumentFactory.getInstance().createElement("set", NAMESPACE); if (first != null) { final Element firstElement; firstElement = set.addElement("first"); firstElement.setText(first.toString()); if (firstIndex != null) { firstElement.addAttribute("index", firstIndex.toString()); } } if (last != null) { set.addElement("last").setText(last.toString()); } if (count != null) { set.addElement("count").setText(count.toString()); } return set; }
@Override public String buildXml(Report report) { try { Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("report"); root.addAttribute("name", report.getName()); writeTemplates(report, root); writeInputParameters(report, root); writeValueFormats(report, root); writeRootBand(report, root); StringWriter stringWriter = new StringWriter(); new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()).write(document); return stringWriter.toString(); } catch (IOException e) { throw new ReportingException(e); } }
private Document createDocument(final Reflections reflections) { Store map = reflections.getStore(); Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("Reflections"); for (String indexName : map.keySet()) { Element indexElement = root.addElement(indexName); for (String key : map.get(indexName).keySet()) { Element entryElement = indexElement.addElement("entry"); entryElement.addElement("key").setText(key); Element valuesElement = entryElement.addElement("values"); for (String value : map.get(indexName).get(key)) { valuesElement.addElement("value").setText(value); } } } return document; }
public static DocumentFactory getDocumentFactory() { ClassLoader cl = ClassLoaderHelper.getContextClassLoader(); DocumentFactory factory; try { Thread.currentThread().setContextClassLoader( XMLHelper.class.getClassLoader() ); factory = DocumentFactory.getInstance(); } finally { Thread.currentThread().setContextClassLoader( cl ); } return factory; }
/** * Convert the BugCollection into a dom4j Document object. * * @param project the Project from which the BugCollection was generated * @return the Document representing the BugCollection as a dom4j tree */ public Document toDocument(Project project) { DocumentFactory docFactory = new DocumentFactory(); Document document = docFactory.createDocument(); Dom4JXMLOutput treeBuilder = new Dom4JXMLOutput(document); try { writeXML(treeBuilder, project); } catch (IOException e) { // Can't happen } return document; }
/** * 合并mybatis配置文件 */ public Document SQLConfigMap() { Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("UTF-8"); DocumentFactory documentFactory = new DocumentFactory(); DocumentType docType = documentFactory.createDocType("configuration", "-//mybatis.org//DTD Config 3.0//EN", "http://mybatis.org/dtd/mybatis-3-config.dtd"); doc.setDocType(docType); Element rootElement = doc.addElement("configuration"); rootElement.addElement("typeAliases"); rootElement.addElement("mappers"); return doc; }
public XMLBuilder(String strDocXml, String strEncoding,Map<String, String> uris) throws XMLException { strDocXml = "<?xml version=\"1.0\" encoding=\"" + strEncoding + "\"?>\n" + strDocXml; try { DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); dom4JDocument = factory.createDocument(); dom4JDocument = DocumentHelper.parseText(strDocXml); root = dom4JDocument.getRootElement(); }catch (Exception e) { throw new XMLException(e.getMessage()); } }
public void testCompositeId() throws Exception { Element a = DocumentFactory.getInstance().createElement( "a" ); a.addAttribute("id", "1"); a.addElement("x").setText("foo bar"); //Element bs = a.addElement("bs"); Element b = a.addElement("b"); //b.addElement("bId").setText("1"); //b.addElement("aId").setText("1"); b.addAttribute("bId", "1"); b.addAttribute("aId", "1"); b.setText("foo foo"); b = a.addElement("b"); //b.addElement("bId").setText("2"); //b.addElement("aId").setText("1"); b.addAttribute("bId", "2"); b.addAttribute("aId", "1"); b.setText("bar bar"); Session s = openSession(); Transaction t = s.beginTransaction(); s.persist("A", a); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); a = (Element) s.createCriteria("A").uniqueResult(); assertEquals( a.elements("b").size(), 2 ); print(a); s.delete("A", a); t.commit(); s.close(); }
public void testDom4jSave() { TestData testData = new TestData(); testData.create(); Session pojos = openSession(); Transaction txn = pojos.beginTransaction(); org.hibernate.Session dom4j = pojos.getSession( EntityMode.DOM4J ); Element stock = DocumentFactory.getInstance().createElement( "stock" ); stock.addElement( "tradeSymbol" ).setText( "IBM" ); Element val = stock.addElement( "currentValuation" ).addElement( "valuation" ); val.appendContent( stock ); val.addElement( "valuationDate" ).setText( new java.util.Date().toString() ); val.addElement( "value" ).setText( "121.00" ); dom4j.save( Stock.class.getName(), stock ); dom4j.flush(); txn.rollback(); pojos.close(); assertTrue( !pojos.isOpen() ); assertTrue( !dom4j.isOpen() ); prettyPrint( stock ); testData.destroy(); }
public Object evaluate(TaskRequest req, TaskResponse res) { Branch rslt = new DocumentFactory().createDocument(); if (name != null) { rslt = rslt.addElement((String) name.evaluate(req, res)); } return rslt; }
private Element buildAccountElement(Account account) { Element element = DocumentFactory.getInstance().createElement(ELEMENT_ACCOUNT); element.addElement(ELEMENT_ACCOUNT_ID).setText(account.getId()); element.addElement(ELEMENT_ACCOUNT_NAME).setText(account.getName()); element.addElement(ELEMENT_ACCOUNT_EMAIL).setText(account.getEmail()); element.addElement(ELEMENT_ACCOUNT_PASSWORD).setText(account.getPassword()); element.addElement(ELEMENT_ACCOUNT_ACTIVATED).setText(account.isActivated() ? "true" : "false"); return element; }
private static void handleShadingSpecialCases(){ String shadePrefix = PackageInfo.getShadedPackageForThirdPartyLibraries()+"."; if(! DocumentFactory.class.getName().startsWith(shadePrefix)){ //if not shaded (eg in system tests), then nothing to do return; } String defaultFactory = System.getProperty("org.dom4j.factory", "org.dom4j.DocumentFactory"); String defaultDomSingletonClass= System.getProperty( "org.dom4j.dom.DOMDocumentFactory.singleton.strategy", "org.dom4j.util.SimpleSingleton"); String defaultSingletonClass = System.getProperty( "org.dom4j.DocumentFactory.singleton.strategy", "org.dom4j.util.SimpleSingleton"); System.setProperty("org.dom4j.factory" , shadePrefix + defaultFactory); System.setProperty("org.dom4j.dom.DOMDocumentFactory.singleton.strategy" , shadePrefix + defaultDomSingletonClass); System.setProperty("org.dom4j.DocumentFactory.singleton.strategy" , shadePrefix + defaultSingletonClass); DocumentFactory.getInstance(); //force loading DOMDocumentFactory.getInstance(); //restore in case SUT uses its own dom4j System.setProperty("org.dom4j.factory" ,defaultFactory); System.setProperty("org.dom4j.dom.DOMDocumentFactory.singleton.strategy", defaultDomSingletonClass); System.setProperty("org.dom4j.DocumentFactory.singleton.strategy", defaultSingletonClass); }
@Test public void testAddingAnonymousUser() throws UnauthorizedException { UserCreate request = new UserCreate(); request.setDisplayName("AnonUser1"); request.setApiKey("3171f18a-9fcc-4e84-8cb9-aad6ea7bf017"); request.setAppId(sAppID); request.setUserId("deviceid-1"); request.setEmail("unknown"); request.setCreateMode(UserCreateMode.GUEST); request.setPriKey("guestsecretcode"); DocumentFactory factory = new DocumentFactory(); final Element element = factory.createElement(Constants.MMX, Constants.MMX_NS_USER); element.addAttribute(Constants.MMX_ATTR_COMMAND, "create"); element.setText(request.toJson()); IQ userCreateIQ = new IQ(); userCreateIQ.setChildElement(element); userCreateIQ.setType(IQ.Type.set); MMXUserHandler userHandler = new StubMMXUserHandler("stubbed mmx user handler"); IQ response = userHandler.handleCreateUser(userCreateIQ, element.getText()); assertNotNull(response); IQ.Type type = response.getType(); String payload = response.getChildElement().getStringValue(); assertNotNull("Null payload", payload); MMXStatus status = MMXStatus.fromJson(payload); int code = status.getCode(); String message = status.getMessage(); assertTrue(message.length() > 0); assertEquals(UserOperationStatusCode.USER_CREATED.getCode(), code); }
@Test public void testQueryUsers1() throws UnauthorizedException { List<MMXAttribute<UserQuery.Type>> clist = new ArrayList<MMXAttribute<UserQuery.Type>>(4); { MMXAttribute<UserQuery.Type> c = new MMXAttribute<UserQuery.Type>(UserQuery.Type.displayName, "login3"); clist.add(c); } UserQuery.BulkSearchRequest query = new UserQuery.BulkSearchRequest(clist, null); DocumentFactory factory = new DocumentFactory(); final Element element = factory.createElement(Constants.MMX, Constants.MMX_NS_USER); element.addAttribute(Constants.MMX_ATTR_COMMAND, Constants.UserCommand.query.name()); element.setText(query.toJson()); IQ queryIQ = new IQ(); queryIQ.setFrom(sFrom); queryIQ.setChildElement(element); queryIQ.setType(IQ.Type.set); MMXUserHandler userHandler = new StubMMXUserHandler("stubbed mmx user handler"); IQ response = userHandler.handleQueryUser(queryIQ, sFrom, sAppID, element.getText()); assertNotNull(response); IQ.Type type = response.getType(); assertEquals("Non matching type", IQ.Type.result, type); String payload = response.getChildElement().getStringValue(); assertNotNull("Null payload", payload); UserQuery.Response responseList = UserQuery.Response.fromJson(payload); List<UserInfo> userList = responseList.getUsers(); assertTrue("User list is empty", !userList.isEmpty()); }
private String getQuestionPreview(final Item theItem) { final Element el = DocumentFactory.getInstance().createElement("dummy"); theItem.addToElement(el); final StringBuilder sb = new StringBuilder(); final org.olat.lms.ims.qti.container.qtielements.Item foo = new org.olat.lms.ims.qti.container.qtielements.Item((Element) el.elements().get(0)); foo.render(sb, renderInstructions); final String previewWithFormattedMathElements = Formatter.formatLatexFormulas(sb.toString()); final Filter filter = FilterFactory.getBaseURLToMediaRelativeURLFilter(qtiPackage.getMediaBaseURL()); return filter.filter(previewWithFormattedMathElements); }
private static void addStaticsPath(final Element el_in, final AssessmentInstance ai) { Element el_staticspath = (Element) el_in.selectSingleNode(STATICS_PATH); if (el_staticspath == null) { final DocumentFactory df = DocumentFactory.getInstance(); el_staticspath = df.createElement(STATICS_PATH); final Resolver resolver = ai.getResolver(); el_staticspath.addAttribute("ident", resolver.getStaticsBaseURI()); el_in.add(el_staticspath); } }
protected Element parseLaneToXml(Lane lane){ Element element = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':' + BpmnXMLConstants.ELEMENT_LANE, BpmnXMLConstants.BPMN2_NAMESPACE); element.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, lane.getId()); element.addAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, lane.getName()); LaneSet laneSet= lane.getChildLaneSet(); if(laneSet != null){ List<Lane> lanes = laneSet.getLanes(); Element laneSetElement = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':' + BpmnXMLConstants.ELEMENT_CHILDLANESET, BpmnXMLConstants.BPMN2_NAMESPACE); laneSetElement.addAttribute("xsi:type", "bpmn2:tLaneSet"); laneSetElement.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, laneSet.getId()); laneSetElement.addAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, laneSet.getName()); if(lanes != null){ for(Lane tmpLane : lanes){ Element tmpElement = parseLaneToXml(tmpLane); laneSetElement.add(tmpElement); } } element.add(laneSetElement); } List<String> flowNodeRefs = lane.getFlowElementRefs(); if(flowNodeRefs != null){ for(String tmpRef : flowNodeRefs){ Element elementFlowRef = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':' + BpmnXMLConstants.ELEMENT_FLOWNODEREF, BpmnXMLConstants.BPMN2_NAMESPACE); elementFlowRef.addText(tmpRef); element.add(elementFlowRef); } } return element; }
/** * 将bpmnModel转换成documnet * * @param model * bpmn模型 */ public Document convertToXML(BpmnModel model) { if (null == model) { throw new BpmnConverterException("模型转换XML失败,模型实例不能为空!"); } DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); Element element = factory.createElement(BpmnXMLConstants.BPMN2_PREFIX + ':' + BpmnXMLConstants.ELEMENT_DEFINITIONS, BpmnXMLConstants.BPMN2_NAMESPACE); element.addNamespace(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE); element.addNamespace(BpmnXMLConstants.DC_PREFIX, BpmnXMLConstants.DC_NAMESPACE); element.addNamespace(BpmnXMLConstants.DI_PREFIX, BpmnXMLConstants.DI_NAMESPACE); element.addNamespace(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.BPMNDI_NAMESPACE); element.addNamespace(BpmnXMLConstants.FOXBPM_PREFIX, BpmnXMLConstants.FOXBPM_NAMESPACE); element.addNamespace(BpmnXMLConstants.XSD_PREFIX, BpmnXMLConstants.XSD_NAMESPACE); element.addNamespace(BpmnXMLConstants.EMPTY_STRING, BpmnXMLConstants.XMLNS_NAMESPACE); // 添加属性 element.addAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, BpmnXMLConstants.XMLNS_NAMESPACE); element.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "Definitions_1"); doc.add(element); // 流程转换 try { for (Iterator<Process> iterator = model.getProcesses().iterator(); iterator.hasNext();) { ProcessExport.writeProcess(iterator.next(), element); } // 位置坐标转换 BPMNDIExport.writeBPMNDI(model, element); } catch (Exception e) { LOGGER.error("模型转换XML失败,流程名" + model.getProcesses().get(0).getName(), e); if (e instanceof BpmnConverterException) { throw (BpmnConverterException) e; } else { throw new BpmnConverterException("模型转换XML失败,流程名:" + model.getProcesses().get(0).getName(), e); } } return doc; }
public static Job getSnapshotJobWithSbforgeAsSeed() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { Constructor<Job> c = ReflectUtils.getPrivateConstructor( Job.class, Long.class, Map.class, String.class, Boolean.TYPE, Long.TYPE,Long.TYPE, Long.TYPE, JobStatus.class, String.class, Document.class, String.class, Integer.TYPE, Long.class); HarvestChannel lowChan = new HarvestChannel("SNAPSHOT", true, true, ""); return c.newInstance(42L, Collections.<String, String>emptyMap(), lowChan.getName(), lowChan.isSnapshot(), -1L, -1L, 0L, JobStatus.STARTED, "default_template", DocumentFactory.getInstance().createDocument(), "http://sbforge.org", 1, null); }
/** * Returns an Element with the privacy list XML representation. * * @return an Element with the privacy list XML representation. */ public Element asElement() { //Element listElement = DocumentFactory.getInstance().createDocument().addElement("list"); Element listElement = DocumentFactory.getInstance().createDocument() .addElement("list", "jabber:iq:privacy"); listElement.addAttribute("name", getName()); // Add the list items to the result for (PrivacyItem item : items) { listElement.add(item.asElement()); } return listElement; }
public EternaSAXContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler) { super(documentFactory, elementHandler); if (documentFactory instanceof EternaDocumentFactory) { this.documentFactory = (EternaDocumentFactory) documentFactory; } }