List of usage examples for org.dom4j Element getData
Object getData();
From source file:org.orbeon.oxf.xforms.XFormsContextStack.java
License:Open Source License
public void pushBinding(String ref, String context, String nodeset, String modelId, String bindId, Element bindingElement, NamespaceMapping bindingElementNamespaceMapping, String sourceEffectiveId, Scope scope, boolean handleNonFatal) { assert scope != null; final LocationData locationData; {/*from w w w . j a va2 s . co m*/ if (keepLocationData) locationData = (bindingElement == null) ? container.getLocationData() : new ExtendedLocationData((LocationData) bindingElement.getData(), "pushing XForms control binding", bindingElement); else locationData = null; } try { // Handle scope // The new binding evaluates against a base binding context which must be in the same scope final BindingContext baseBindingContext = getBindingContext(scope); // Set context final String tempSourceEffectiveId = functionContext.sourceEffectiveId(); if (sourceEffectiveId != null) { functionContext.setSourceEffectiveId(sourceEffectiveId); } // Handle model final XFormsModel newModel; final boolean isNewModel; if (modelId != null) { final XBLContainer resolutionScopeContainer = container.findScopeRoot(scope); final XFormsObject o = resolutionScopeContainer.resolveObjectById(sourceEffectiveId, modelId, null); if (!(o instanceof XFormsModel)) { // Invalid model id // NOTE: We used to dispatch xforms-binding-exception, but we want to be able to recover if (!handleNonFatal) throw new ValidationException("Reference to non-existing model id: " + modelId, locationData); // Default to not changing the model newModel = baseBindingContext.model(); isNewModel = false; } else { newModel = (XFormsModel) o; isNewModel = newModel != baseBindingContext.model();// don't say it's a new model unless it has really changed } } else { newModel = baseBindingContext.model(); isNewModel = false; } // Handle nodeset final boolean isNewBind; final RuntimeBind bind; final int newPosition; final List<Item> newNodeset; final boolean hasOverriddenContext; final Item contextItem; { if (bindId != null) { // Resolve the bind id to a nodeset // NOTE: For now, only the top-level models in a resolution scope are considered final XBLContainer resolutionScopeContainer = container.findScopeRoot(scope); final XFormsObject o = resolutionScopeContainer.resolveObjectById(sourceEffectiveId, bindId, baseBindingContext.getSingleItem()); if (o == null && resolutionScopeContainer.containsBind(bindId)) { // The bind attribute was valid for this scope, but no runtime object was found for the bind // This can happen e.g. if a nested bind is within a bind with an empty nodeset bind = null; newNodeset = XFormsConstants.EMPTY_ITEM_LIST; hasOverriddenContext = false; contextItem = null; isNewBind = true; newPosition = 0; } else if (!(o instanceof RuntimeBind)) { // The bind attribute did not resolve to a bind // NOTE: We used to dispatch xforms-binding-exception, but we want to be able to recover if (!handleNonFatal) throw new ValidationException("Reference to non-existing bind id: " + bindId, locationData); // Default to an empty binding bind = null; newNodeset = XFormsConstants.EMPTY_ITEM_LIST; hasOverriddenContext = false; contextItem = null; isNewBind = true; newPosition = 0; } else { bind = (RuntimeBind) o; newNodeset = bind.nodeset; hasOverriddenContext = false; contextItem = baseBindingContext.getSingleItem(); isNewBind = true; newPosition = Math.min(newNodeset.size(), 1); } } else if (ref != null || nodeset != null) { bind = null; // Check whether there is an optional context (XForms 1.1, likely generalized in XForms 1.2) final BindingContext evaluationContextBinding; if (context != null) { // Push model and context pushTemporaryContext(this.head, baseBindingContext, baseBindingContext.getSingleItem());// provide context information for the context() function pushBinding(null, null, context, modelId, null, null, bindingElementNamespaceMapping, sourceEffectiveId, scope, handleNonFatal); hasOverriddenContext = true; final BindingContext newBindingContext = this.head; contextItem = newBindingContext.getSingleItem(); evaluationContextBinding = newBindingContext; } else if (isNewModel) { // Push model only pushBinding(null, null, null, modelId, null, null, bindingElementNamespaceMapping, sourceEffectiveId, scope, handleNonFatal); hasOverriddenContext = false; final BindingContext newBindingContext = this.head; contextItem = newBindingContext.getSingleItem(); evaluationContextBinding = newBindingContext; } else { hasOverriddenContext = false; contextItem = baseBindingContext.getSingleItem(); evaluationContextBinding = baseBindingContext; } if (false) { // NOTE: This is an attempt at allowing evaluating a binding even if no context is present. // But this doesn't work properly. E.g.: // // <xf:group ref="()"> // <xf:input ref="."/> // // Above must end up with an empty binding for xf:input, while: // // <xf:group ref="()"> // <xf:input ref="instance('foobar')"/> // // Above must end up with a non-empty binding IF it was to be evaluated. // // Now the second condition above should not happen anyway, because the content of the group // is non-relevant anyway. But we do have cases now where this happens, so we can't enable // the code below naively. // // We could enable it if we knew statically that the expression did not depend on the // context though, but right now we don't. final boolean isDefaultContext; final List<Item> evaluationNodeset; final int evaluationPosition; if (evaluationContextBinding.getNodeset().size() > 0) { isDefaultContext = false; evaluationNodeset = evaluationContextBinding.getNodeset(); evaluationPosition = evaluationContextBinding.getPosition(); } else { isDefaultContext = true; evaluationNodeset = DEFAULT_CONTEXT; evaluationPosition = 1; } if (!isDefaultContext) { // Provide context information for the context() function pushTemporaryContext(this.head, evaluationContextBinding, evaluationContextBinding.getSingleItem()); } // Use updated binding context to set model functionContext.setModel(evaluationContextBinding.model()); List<Item> result; try { result = XPathCache.evaluateKeepItems(evaluationNodeset, evaluationPosition, ref != null ? ref : nodeset, bindingElementNamespaceMapping, evaluationContextBinding.getInScopeVariables(), XFormsContainingDocument.getFunctionLibrary(), functionContext, null, locationData, containingDocument.getRequestStats().getReporter()); } catch (Exception e) { if (handleNonFatal) { XFormsError.handleNonFatalXPathError(container, e); result = XFormsConstants.EMPTY_ITEM_LIST; } else { throw e; } } newNodeset = result; if (!isDefaultContext) { popBinding(); } } else { if (evaluationContextBinding.getNodeset().size() > 0) { // Evaluate new XPath in context if the current context is not empty // TODO: in the future, we should allow null context for expressions that do not depend on the context // NOTE: We prevent evaluation if the context was empty. However there are cases where this // should be allowed, if the expression does not depend on the context. Ideally, we would know // statically whether an expression depends on the context or not, and take separate action if // that's the case. Currently, such an expression will produce an XPathException. // It might be the case that when we implement non-evaluation of relevant subtrees, this won't // be an issue anymore, and we can simply allow evaluation of such expressions. Otherwise, // static analysis of expressions might provide enough information to handle the two situations. pushTemporaryContext(this.head, evaluationContextBinding, evaluationContextBinding.getSingleItem());// provide context information for the context() function // Use updated binding context to set model functionContext.setModel(evaluationContextBinding.model()); List<Item> result; try { result = XPathCache.evaluateKeepItems(evaluationContextBinding.getNodeset(), evaluationContextBinding.getPosition(), ref != null ? ref : nodeset, bindingElementNamespaceMapping, evaluationContextBinding.getInScopeVariables(), XFormsContainingDocument.getFunctionLibrary(), functionContext, null, locationData, containingDocument.getRequestStats().getReporter()); } catch (Exception e) { if (handleNonFatal) { XFormsError.handleNonFatalXPathError(container, e); result = XFormsConstants.EMPTY_ITEM_LIST; } else { throw e; } } newNodeset = result; popBinding(); } else { // Otherwise we consider we can't evaluate newNodeset = XFormsConstants.EMPTY_ITEM_LIST; } } // Restore optional context if (context != null || isNewModel) { popBinding(); if (context != null) popBinding(); } isNewBind = true; newPosition = 1; } else if (isNewModel && context == null) { // Only the model has changed bind = null; final BindingContext modelBindingContext = getCurrentBindingContextForModel(newModel); if (modelBindingContext != null) { newNodeset = modelBindingContext.getNodeset(); newPosition = modelBindingContext.getPosition(); } else { newNodeset = getCurrentNodeset(newModel); newPosition = 1; } hasOverriddenContext = false; contextItem = baseBindingContext.getSingleItem(); isNewBind = false; } else if (context != null) { bind = null; // Only the context has changed, and possibly the model pushBinding(null, null, context, modelId, null, null, bindingElementNamespaceMapping, sourceEffectiveId, scope, handleNonFatal); { newNodeset = getCurrentNodeset(); newPosition = getCurrentPosition(); isNewBind = false; hasOverriddenContext = true; contextItem = getCurrentSingleItem(); } popBinding(); } else { // No change to anything bind = null; isNewBind = false; newNodeset = baseBindingContext.getNodeset(); newPosition = baseBindingContext.getPosition(); // We set a new context item as the context into which other attributes must be evaluated. E.g.: // // <xf:select1 ref="type"> // <xf:action ev:event="xforms-value-changed" if="context() = 'foobar'"> // // In this case, you expect context() to be updated as follows. // hasOverriddenContext = false; contextItem = baseBindingContext.getSingleItem(); } } // Push new context final String bindingElementId = (bindingElement == null) ? null : XFormsUtils.getElementId(bindingElement); this.head = new BindingContext(this.head, newModel, bind, newNodeset, newPosition, bindingElementId, isNewBind, bindingElement, locationData, hasOverriddenContext, contextItem, scope); // Restore context if (sourceEffectiveId != null) { functionContext.setSourceEffectiveId(tempSourceEffectiveId); } } catch (Exception e) { if (bindingElement != null) { throw OrbeonLocationException.wrapException(e, new ExtendedLocationData(locationData, "evaluating binding expression", bindingElement)); } else { throw OrbeonLocationException.wrapException(e, new ExtendedLocationData(locationData, "evaluating binding expression", bindingElement, new String[] { "ref", ref, "context", context, "nodeset", nodeset, "modelId", modelId, "bindId", bindId })); } } }
From source file:org.orbeon.oxf.xforms.XFormsUtils.java
License:Open Source License
/** * Get the value of an element by trying single-node binding, value attribute, linking attribute, and inline value * (including nested XHTML and xf:output elements). * * This may return an HTML string if HTML is accepted and found, or a plain string otherwise. * * @param container current XBLContainer * @param contextStack context stack for XPath evaluation * @param sourceEffectiveId source effective id for id resolution * @param childElement element to evaluate (xf:label, etc.) * @param acceptHTML whether the result may contain HTML * @param containsHTML whether the result actually contains HTML (null allowed) * @return string containing the result of the evaluation, null if evaluation failed (see comments) *//* ww w .ja v a2s. co m*/ public static String getElementValue(final XBLContainer container, final XFormsContextStack contextStack, final String sourceEffectiveId, final Element childElement, final boolean acceptHTML, final boolean defaultHTML, final boolean[] containsHTML) { // No HTML found by default if (containsHTML != null) containsHTML[0] = defaultHTML; final BindingContext currentBindingContext = contextStack.getCurrentBindingContext(); // "the order of precedence is: single node binding attributes, linking attributes, inline text." // Try to get single node binding { final boolean hasSingleNodeBinding = currentBindingContext.isNewBind(); if (hasSingleNodeBinding) { final Item boundItem = currentBindingContext.getSingleItem(); final String tempResult = DataModel.getValue(boundItem); if (tempResult != null) { return (acceptHTML && containsHTML == null) ? XMLUtils.escapeXMLMinimal(tempResult) : tempResult; } else { // There is a single-node binding but it doesn't point to an acceptable item return null; } } } // Try to get value attribute // NOTE: This is an extension attribute not standard in XForms 1.0 or 1.1 { final String valueAttribute = childElement.attributeValue(XFormsConstants.VALUE_QNAME); final boolean hasValueAttribute = valueAttribute != null; if (hasValueAttribute) { final List<Item> currentNodeset = currentBindingContext.getNodeset(); if (currentNodeset != null && currentNodeset.size() > 0) { String tempResult; try { tempResult = XPathCache.evaluateAsString(currentNodeset, currentBindingContext.getPosition(), valueAttribute, container.getNamespaceMappings(childElement), contextStack.getCurrentVariables(), XFormsContainingDocument.getFunctionLibrary(), contextStack.getFunctionContext(sourceEffectiveId), null, (LocationData) childElement.getData(), container.getContainingDocument().getRequestStats().getReporter()); } catch (Exception e) { XFormsError.handleNonFatalXPathError(container, e); tempResult = ""; } finally { contextStack.returnFunctionContext(); } return (acceptHTML && containsHTML == null) ? XMLUtils.escapeXMLMinimal(tempResult) : tempResult; } else { // There is a value attribute but the evaluation context is empty return null; } } } // Try to get linking attribute // NOTE: This is deprecated in XForms 1.1 { final String srcAttributeValue = childElement.attributeValue(XFormsConstants.SRC_QNAME); final boolean hasSrcAttribute = srcAttributeValue != null; if (hasSrcAttribute) { try { // NOTE: This should probably be cached, but on the other hand almost nobody uses @src final String tempResult = retrieveSrcValue(srcAttributeValue); if (containsHTML != null) containsHTML[0] = false; // NOTE: we could support HTML if the media type returned is text/html return (acceptHTML && containsHTML == null) ? XMLUtils.escapeXMLMinimal(tempResult) : tempResult; } catch (IOException e) { // Dispatch xforms-link-error to model final XFormsModel currentModel = currentBindingContext.model(); // NOTE: xforms-link-error is no longer in XForms 1.1 starting 2009-03-10 Dispatch.dispatchEvent(new XFormsLinkErrorEvent(currentModel, srcAttributeValue, e)); // Exception when dereferencing the linking attribute return null; } } } // Try to get inline value { final StringBuilder sb = new StringBuilder(20); // Visit the subtree and serialize // NOTE: It is a little funny to do our own serialization here, but the alternative is to build a DOM and // serialize it, which is not trivial because of the possible interleaved xf:output's. Furthermore, we // perform a very simple serialization of elements and text to simple (X)HTML, not full-fledged HTML or XML // serialization. Dom4jUtils.visitSubtree(childElement, new LHHAElementVisitorListener(container, contextStack, sourceEffectiveId, acceptHTML, defaultHTML, containsHTML, sb, childElement)); if (acceptHTML && containsHTML != null && !containsHTML[0]) { // We went through the subtree and did not find any HTML // If the caller supports the information, return a non-escaped string so we can optimize output later return XMLUtils.unescapeXMLMinimal(sb.toString()); } else { // We found some HTML, just return it return sb.toString(); } } }
From source file:org.orbeon.oxf.xforms.XFormsUtils.java
License:Open Source License
/** * Resolve a URI string against an element, taking into account ancestor xml:base attributes for * the resolution.//from w w w.j ava2s . co m * * @param element element used to start resolution (if null, no resolution takes place) * @param baseURI optional base URI * @param uri URI to resolve * @return resolved URI */ public static URI resolveXMLBase(Element element, String baseURI, String uri) { try { // Allow for null Element if (element == null) return new URI(uri); final List<String> xmlBaseValues = new ArrayList<String>(); // Collect xml:base values Element currentElement = element; do { final String xmlBaseAttribute = currentElement.attributeValue(XMLConstants.XML_BASE_QNAME); if (xmlBaseAttribute != null) xmlBaseValues.add(xmlBaseAttribute); currentElement = currentElement.getParent(); } while (currentElement != null); // Append base if needed if (baseURI != null) xmlBaseValues.add(baseURI); // Go from root to leaf Collections.reverse(xmlBaseValues); xmlBaseValues.add(uri); // Resolve paths from root to leaf URI result = null; for (final String currentXMLBase : xmlBaseValues) { final URI currentXMLBaseURI = new URI(currentXMLBase); result = (result == null) ? currentXMLBaseURI : result.resolve(currentXMLBaseURI); } return result; } catch (URISyntaxException e) { throw new ValidationException("Error while resolving URI: " + uri, e, (element != null) ? (LocationData) element.getData() : null); } }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
public static String makeSystemId(final Element e) { final LocationData ld = (LocationData) e.getData(); final String ldSid = ld == null ? null : ld.getSystemID(); return ldSid == null ? DOMGenerator.DefaultContext : ldSid; }
From source file:org.suren.autotest.web.framework.code.DefaultXmlCodeGenerator.java
License:Apache License
/** * @param document/*from ww w .j av a 2 s . c om*/ */ private void read(Document doc) { SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext(); simpleNamespaceContext.addNamespace("ns", "http://surenpi.com"); DefaultXPath xpath = new DefaultXPath("/ns:autotest/ns:pages"); xpath.setNamespaceContext(simpleNamespaceContext); Element pagesEle = (Element) xpath.selectSingleNode(doc); String pagePackage = pagesEle.attributeValue("pagePackage", ""); if (StringUtils.isNotBlank(pagePackage)) { pagePackage = (pagePackage.trim() + "."); } // pages parse progress xpath = new DefaultXPath("/ns:autotest/ns:pages/ns:page"); xpath.setNamespaceContext(simpleNamespaceContext); @SuppressWarnings("unchecked") List<Element> pageNodes = xpath.selectNodes(doc); if (pageNodes != null) { for (Element ele : pageNodes) { String pageClsStr = ele.attributeValue("class"); if (pageClsStr == null) { logger.warn("can not found class attribute."); continue; } pageClsStr = (pagePackage + pageClsStr); Object commentObj = ele.getData(); if (commentObj != null) { pageCommentMap.put(pageClsStr, commentObj.toString().trim()); } try { List<AutoField> fieldList = new ArrayList<AutoField>(); pageFieldMap.put(pageClsStr, fieldList); parsePage(pageClsStr, ele, fieldList); } catch (Exception e) { logger.error("page element parse error.", e); } } } }
From source file:org.suren.autotest.web.framework.code.DefaultXmlCodeGenerator.java
License:Apache License
/** * ??Page// ww w. j a va 2 s . c o m * * @param pageClsStr * @param dataSrcClsStr * @param ele * @param fieldList */ private void parsePage(final String pageClsStr, Element ele, final List<AutoField> fieldList) throws Exception { ele.accept(new VisitorSupport() { @Override public void visit(Element node) { if (!"field".equals(node.getName())) { return; } String fieldName = node.attributeValue("name"); String type = node.attributeValue("type"); if (fieldName == null || "".equals(fieldName) || type == null || "".equals(type)) { return; } AutoField autoField = new AutoField(fieldName, type); Object commentObj = node.getData(); if (commentObj != null) { autoField.setComment(commentObj.toString().trim()); } fieldList.add(autoField); } }); }
From source file:org.talend.designer.core.ui.editor.properties.controllers.RetrieveSchemaHelper.java
License:Open Source License
public static Command retrieveSchemasCommand(Node node) { IElementParameter param = node.getElementParameter("SCHEMA"); IMetadataTable inputMeta = node.getMetadataFromConnector("FLOW"); IMetadataTable inputMetaCopy = inputMeta.clone(true); IElementParameter outParam = node.getElementParameter("SCHEMA_OUT"); IMetadataTable outputMeta = node.getMetadataFromConnector(outParam.getContext()); IMetadataTable outputMetaCopy = outputMeta.clone(true); File xmlFile = new File( TalendTextUtils.removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString())); if (!xmlFile.exists()) try {//from ww w. ja v a 2 s .c o m xmlFile.createNewFile(); } catch (IOException e1) { ExceptionHandler.process(e1); } SAXReader saxReader = new SAXReader(); Document document; AutoApi a = null; try { // get the schema file from server a = new AutoApi(); String hostName = TalendTextUtils .removeQuotes(node.getElementParameter("HOSTNAME").getValue().toString()); int port = Integer .parseInt(TalendTextUtils.removeQuotes(node.getElementParameter("PORT").getValue().toString())); String mandant = TalendTextUtils .removeQuotes(node.getElementParameter("MANDANT").getValue().toString()); String userName = TalendTextUtils .removeQuotes(node.getElementParameter("USERNAME").getValue().toString()); String passWord = TalendTextUtils .removeQuotes(node.getElementParameter("PASSWORD").getValue().toString()); String jobDir = TalendTextUtils.removeQuotes(node.getElementParameter("JOB_DIR").getValue().toString()); String jobName = TalendTextUtils .removeQuotes(node.getElementParameter("JOB_NAME").getValue().toString()); String jobDef = TalendTextUtils .removeQuotes(node.getElementParameter("PATH_JOBDEF").getValue().toString()); a.openConnection(hostName, port, mandant, userName, passWord); a.getJobDefinitionFile(jobDir, jobName, jobDef); document = saxReader.read(xmlFile); List inputList = document .selectNodes("//Job//Lines//Line//Steps//Input//Sources//Source//Format//Fields//Field"); List inputMetaColumnList = new ArrayList<MetadataColumn>(); for (int i = 0; i < inputList.size(); i++) { IMetadataColumn imc = new MetadataColumn(); DefaultElement de = (DefaultElement) inputList.get(i); Element nameElement = de.element("Name"); imc.setLabel(nameElement.getData().toString()); Element lengthElement = de.element("Length"); if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) { imc.setLength(Integer.parseInt(lengthElement.getData().toString())); } Element typeElement = de.element("Type"); JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString()); if (javaType != null) { imc.setTalendType(javaType.getId()); } else { imc.setTalendType(JavaTypesManager.STRING.getId()); } inputMetaColumnList.add(imc); } inputMetaCopy.setListColumns(inputMetaColumnList); List outputList = document .selectNodes("//Job//Lines//Line//Steps//Output//Targets//Target//Format//Fields//Field"); List outputMetaColumnList = new ArrayList<MetadataColumn>(); for (int i = 0; i < outputList.size(); i++) { IMetadataColumn imc = new MetadataColumn(); DefaultElement de = (DefaultElement) outputList.get(i); Element nameElement = de.element("Name"); imc.setLabel(nameElement.getData().toString()); Element lengthElement = de.element("Length"); if (!"".equals(lengthElement.getData().toString()) && !"0".equals(lengthElement.getData().toString())) { imc.setLength(Integer.parseInt(lengthElement.getData().toString())); } Element typeElement = de.element("Type"); JavaType javaType = JavaTypesManager.getJavaTypeFromName(typeElement.getData().toString()); if (javaType != null) { imc.setTalendType(javaType.getId()); } else { imc.setTalendType(JavaTypesManager.STRING.getId()); } outputMetaColumnList.add(imc); } outputMetaCopy.setListColumns(outputMetaColumnList); // set advanced setting info DefaultElement de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//FieldSeparator"); int separator = Integer.parseInt(de.getData().toString()); node.getElementParameter("IN_FIELD_SEP") .setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//Record//HeaderRecordCount"); node.getElementParameter("IN_HEADER_COUNT").setValue(de.getData().toString()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//Directory"); node.getElementParameter("IN_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation//FileName"); node.getElementParameter("IN_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Input//Sources//Source//Format//FileInfo//FileLocation"); node.getElementParameter("IN_MODE").setValue(de.attribute("Mode").getValue()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//FieldSeparator"); separator = Integer.parseInt(de.getData().toString()); node.getElementParameter("OUT_FIELD_SEP") .setValue(TalendTextUtils.addQuotes(new Character((char) separator).toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//Record//HeaderRecordCount"); node.getElementParameter("OUT_HEADER_COUNT").setValue(de.getData().toString()); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//Directory"); node.getElementParameter("OUT_DIR").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation//FileName"); node.getElementParameter("OUT_FILENAME").setValue(TalendTextUtils.addQuotes(de.getData().toString())); de = (DefaultElement) document.selectObject( "//Job//Lines//Line//Steps//Output//Targets//Target//Format//FileInfo//FileLocation"); node.getElementParameter("OUT_MODE").setValue(de.attribute("Mode").getValue()); } catch (Exception e) { ExceptionHandler.process(e); } finally { try { a.closeConnection(); } catch (Exception e) { ExceptionHandler.process(e); } } CompoundCommand cc = new CompoundCommand(); cc.add(new ChangeMetadataCommand(node, param, inputMeta, inputMetaCopy)); cc.add(new ChangeMetadataCommand(node, param, outputMeta, outputMetaCopy)); return cc; }
From source file:us.mn.state.health.lims.dataexchange.aggregatereporting.IndicatorAggregationReportingServlet.java
License:Mozilla Public License
private boolean authenticated(Document sentIndicators) { Element userElement = sentIndicators.getRootElement().element("user"); Element passwordElement = sentIndicators.getRootElement().element("drowssap"); if (userElement == null || passwordElement == null) { return false; }//from ww w . ja va 2s .co m String user = (String) userElement.getData(); String password = (String) passwordElement.getData(); Login login = new Login(); login.setLoginName(user); login.setPassword(password); Login loginInfo = loginDAO.getValidateLogin(login); return loginInfo != null; }
From source file:us.mn.state.health.lims.plugin.PluginLoader.java
License:Mozilla Public License
private boolean loadFromXML(JarFile jar, JarEntry entry) { try {//from www.ja v a 2 s . co m URL url = new URL("jar:file:///" + jar.getName() + "!/"); InputStream input = jar.getInputStream(entry); String xml = IOUtils.toString(input, "UTF-8"); //System.out.println(xml); Document doc = DocumentHelper.parseText(xml); Element versionElement = doc.getRootElement().element(VERSION); if (!SUPPORTED_VERSION.equals(versionElement.getData())) { System.out.println("Unsupported version number. Expected " + SUPPORTED_VERSION + " got " + versionElement.getData()); return false; } Element analyzerImporter = doc.getRootElement().element(ANALYZER_IMPORTER); if (analyzerImporter != null) { Attribute description = analyzerImporter.element(EXTENSION_POINT).element(DESCRIPTION) .attribute(VALUE); System.out.println("Loading: " + description.getValue()); Attribute path = analyzerImporter.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH); loadActualPlugin(url, path.getValue()); } Element menu = doc.getRootElement().element(MENU); if (menu != null) { Attribute description = menu.element(EXTENSION_POINT).element(DESCRIPTION).attribute(VALUE); System.out.println("Loading: " + description.getValue()); Attribute path = menu.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH); loadActualPlugin(url, path.getValue()); } Element permissions = doc.getRootElement().element(PERMISSION); if (permissions != null) { Attribute description = permissions.element(EXTENSION_POINT).element(DESCRIPTION).attribute(VALUE); Attribute path = permissions.element(EXTENSION_POINT).element(EXTENSION).attribute(PATH); boolean loaded = loadActualPlugin(url, path.getValue()); if (loaded) { System.out.println("Loading: " + description.getValue()); } else { System.out.println("Failed Loading: " + description.getValue()); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return true; }
From source file:wowhead_itemreader.WoWHeadData.java
License:Open Source License
private void addToEngine(Element n) throws Exception { String nodeName = n.getName(); try {// w w w .j a va2s .c o m if (nodeName.equals("item")) { this.itemId = getAttributeValue(n, "id"); } else if (nodeName.equals("name")) { this.name = n.getData().toString(); } else if (nodeName.equals("level")) { this.itemLevel = Integer.parseInt(n.getData().toString()); } else if (nodeName.equals("gearScore")) { this.gearScore = Double.parseDouble(n.getData().toString()); } else if (nodeName.equals("quality")) { this.itemQuality = getAttributeValue(n, "id"); } else if (nodeName.equals("class")) { this.itemClass = getAttributeValue(n, "id"); } else if (nodeName.equals("subclass")) { this.itemSubClass = getAttributeValue(n, "id"); } else if (nodeName.equals("icon")) { this.itemDisplayId = getAttributeValue(n, "displayId"); this.iconName = n.getData().toString(); } else if (nodeName.equals("inventorySlot")) { this.itemInventoryId = getAttributeValue(n, "id"); } else if (nodeName.equals("htmlTooltip")) { this.tooltip = n.getData().toString(); } else if (nodeName.startsWith("json")) { parseJson(n.getData().toString()); } else if (nodeName.startsWith("error")) { this.urlexists = false; throw new Exception(n.getData().toString()); } } catch (NumberFormatException ex) { } }