List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java
License:Open Source License
private void parseMappingElement(Element mappingElement, String name) { final Attribute resourceAttribute = mappingElement.attribute("resource"); final Attribute fileAttribute = mappingElement.attribute("file"); final Attribute jarAttribute = mappingElement.attribute("jar"); final Attribute packageAttribute = mappingElement.attribute("package"); final Attribute classAttribute = mappingElement.attribute("class"); if (resourceAttribute != null) { final String resourceName = resourceAttribute.getValue(); log.debug("session-factory config [{}] named resource [{}] for mapping", name, resourceName); addResource(resourceName);//from w w w .j ava 2s.co m } else if (fileAttribute != null) { final String fileName = fileAttribute.getValue(); log.debug("session-factory config [{}] named file [{}] for mapping", name, fileName); addFile(fileName); } else if (jarAttribute != null) { final String jarFileName = jarAttribute.getValue(); log.debug("session-factory config [{}] named jar file [{}] for mapping", name, jarFileName); addJar(new File(jarFileName)); } else if (packageAttribute != null) { final String packageName = packageAttribute.getValue(); log.debug("session-factory config [{}] named package [{}] for mapping", name, packageName); addPackage(packageName); } else if (classAttribute != null) { final String classAttributeName = classAttribute.getValue(); final List<String> classNames = new ArrayList<String>(); if (classAttributeName.endsWith(".*")) { try { classNames.addAll(getAllAnnotatedClassNames(classAttributeName)); } catch (IOException ioe) { log.error("Could not read class: " + classAttributeName, ioe); } catch (URISyntaxException use) { log.error("Could not read class: " + classAttributeName, use); } } else { classNames.add(classAttributeName); } for (String className : classNames) { try { log.debug("session-factory config [{}] named class [{}] for mapping", name, className); addAnnotatedClass(ReflectHelper.classForName(className)); } catch (Exception e) { throw new MappingException("Unable to load class [ " + className + "] declared in Hibernate configuration <mapping/> entry", e); } } } else { throw new MappingException("<mapping> element in configuration specifies no known attributes"); } }
From source file:com.ibm.cognos.MetaData.java
License:Open Source License
/** * ParseMetaData method will create a vector of MetaData objects by parsing * (using DOM) the metadata XML returned from the content store. Basically a * list of all tables and the columns.//from w w w . j a v a2s . co m * * querySubject = tables queryItems = columns * * @param connection * @param newReport * @param defaultPackageName * @return Vector */ public Vector parseMetaData(CRNConnect connection, ReportObject newReport, String defaultPackageName) { // retrieve the metadata from the selected package to display for // table/column selection. Vector packageMetaData = new Vector(); if (defaultPackageName != null) { Document doc = newReport.getMetadata(connection, defaultPackageName); // returns a list of tables from the QuerySubject tag List tableList = (List) doc.selectNodes("/ResponseRoot/folder/folder/folder/querySubject"); for (int i = 0; i < tableList.size(); i++) { Element eTable = (Element) tableList.get(i); Attribute nameAttrQuerySubject = eTable.attribute("name"); String sTable = nameAttrQuerySubject.getValue(); System.out.println(sTable); MetaData md = new MetaData(); md.setQuerySubject(sTable); // set the current node to be the current QuerySubject Element eCurrent = (Element) doc.selectSingleNode( "/ResponseRoot/folder/folder/folder/querySubject[@name='" + sTable + "']"); // retrieve a list of columns in this table or queryItems from // the current querySubject node. List columnList = (List) eCurrent.selectNodes("queryItem"); Vector metaQueryItems = new Vector(); Vector metaFullNameQueryItems = new Vector(); for (int j = 0; j < columnList.size(); j++) { Element eColumn = (Element) columnList.get(j); Attribute attrQueryItemName = eColumn.attribute("name"); Attribute attrQueryItemRef = eColumn.attribute("_ref"); String sColumn = attrQueryItemName.getValue(); String sFullColumnName = attrQueryItemRef.getValue(); System.out.println(" " + sColumn); metaQueryItems.add(sColumn); metaFullNameQueryItems.add(sFullColumnName); } md.setQueryItem(metaQueryItems); md.setFullNameQueryItems(metaFullNameQueryItems); packageMetaData.add(md); } } else System.out.println("Problem: default package name unavailable."); return packageMetaData; }
From source file:com.itextpdf.rups.view.itext.treenodes.XdpTreeNode.java
License:Open Source License
@Override public String toString() { Node node = getNode();/*ww w . ja v a2s .com*/ if (node instanceof Element) { Element e = (Element) node; return e.getName(); } if (node instanceof Attribute) { Attribute a = (Attribute) node; StringBuffer buf = new StringBuffer(); buf.append(a.getName()); buf.append("=\""); buf.append(a.getValue()); buf.append('"'); return buf.toString(); } if (node instanceof Text) { Text t = (Text) node; return t.getText(); } if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; StringBuffer buf = new StringBuffer("<?"); buf.append(pi.getName()); buf.append(' '); buf.append(pi.getText()); buf.append("?>"); return buf.toString(); } if (node instanceof Document) { return "XFA Document"; } return getNode().toString(); }
From source file:com.jaspersoft.jasperserver.export.ImporterImpl.java
License:Open Source License
protected void process() { Document indexDocument = readIndexDocument(); Element indexRoot = indexDocument.getRootElement(); Properties properties = new Properties(); for (Iterator it = indexRoot.elementIterator(getPropertyElementName()); it.hasNext();) { Element propElement = (Element) it.next(); String propKey = propElement.attribute(getPropertyNameAttribute()).getValue(); Attribute valueAttr = propElement.attribute(getPropertyValueAttribute()); String value = valueAttr == null ? null : valueAttr.getValue(); properties.setProperty(propKey, value); }// w ww.j av a 2s .com input.propertiesRead(properties); Attributes contextAttributes = createContextAttributes(); contextAttributes.setAttribute("sourceJsVersion", properties.getProperty(VERSION_ATTR)); contextAttributes.setAttribute("targetJsVersion", super.getJsVersion()); for (Iterator it = indexRoot.elementIterator(getIndexModuleElementName()); it.hasNext();) { if (Thread.interrupted()) { throw new RuntimeException("Cancelled"); } Element moduleElement = (Element) it.next(); String moduleId = moduleElement.attribute(getIndexModuleIdAttributeName()).getValue(); ImporterModule module = getModuleRegister().getImporterModule(moduleId); if (module == null) { throw new JSException("jsexception.import.module.not.found", new Object[] { moduleId }); } commandOut.debug("Invoking module " + module); contextAttributes.setAttribute("appContext", this.task.getApplicationContext()); ModuleContextImpl moduleContext = new ModuleContextImpl(moduleElement, contextAttributes); module.init(moduleContext); List<String> messages = new ArrayList<String>(); ImportRunMonitor.start(); try { List<String> moduleMessages = module.process(); if (moduleMessages != null) { messages.addAll(moduleMessages); } } finally { ImportRunMonitor.stop(); for (String message : messages) { commandOut.info(message); } } } }
From source file:com.jeeframework.util.xml.XMLProperties.java
License:Open Source License
/** * Removes the given attribute from the XML document. * * @param name the property name to lookup - ie, "foo.bar" * @param attribute the name of the attribute, ie "id" * @return the value of the attribute of the given property or <tt>null</tt> if * it did not exist.//from w w w .j a va 2 s . c o m */ public String removeAttribute(String name, String attribute) { if (name == null || attribute == null) { return null; } String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML hierarchy. Element element = document.getRootElement(); for (String child : propName) { element = element.element(child); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return empty array. break; } } String result = null; if (element != null) { // Get the attribute value and then remove the attribute Attribute attr = element.attribute(attribute); result = attr.getValue(); element.remove(attr); } return result; }
From source file:com.jonschang.ai.network.feedforward.FeedForwardXmlUnmarshaller.java
License:LGPL
public void unmarshal(FeedForward obj, Reader xmlReader) throws XmlException { SAXReader reader = new SAXReader(); Document doc = null;/* ww w .ja v a 2 s . co m*/ try { doc = reader.read(xmlReader); } catch (Exception e) { throw new XmlException("Could not read the Xml document", e); } Element root = doc.getRootElement(); Element current = null; Map<Integer, Neuron> intToNeuronMap = new HashMap<Integer, Neuron>(); Map<Integer, Activator> intToActivatorMap = new HashMap<Integer, Activator>(); int neuronIndex = 0, activators = 0; Attribute attr = null; Neuron neuron = null; Neuron outputNeuron = null; obj.getAllLayers().clear(); // build all the neurons and cache them in an // index-to-neuron map for (Object e : root.elements()) if (e instanceof Element) { current = (Element) e; if (current.getName().compareTo("layers") == 0) { for (Object layerObject : current.elements()) if (((Element) layerObject).getName().compareTo("layer") == 0) { List<Neuron> thisLayer = new ArrayList<Neuron>(); for (Object neuronObject : ((Element) layerObject).elements()) if (((Element) neuronObject).getName().compareTo("neuron") == 0) { neuron = new GenericNeuron(); intToNeuronMap.put(neuronIndex, neuron); attr = ((Element) neuronObject).attribute("threshold"); neuron.setThreshold(Double.valueOf(attr.getValue())); thisLayer.add(neuron); neuronIndex++; } obj.getAllLayers().add(thisLayer); } } else if (current.getName().compareTo("activators") == 0 && current.elements().size() > 0) { for (Object a : current.elements()) if (a instanceof Element) { Element activator = (Element) a; ActivatorXmlFactory axf = new ActivatorXmlFactory(); Activator activatorObject = null; String clazz = activator.attributeValue("type"); try { activatorObject = (Activator) Class.forName(clazz).newInstance(); @SuppressWarnings(value = "unchecked") XmlUnmarshaller<Activator> m = (XmlUnmarshaller<Activator>) axf .getUnmarshaller(activatorObject); m.unmarshal(activatorObject, new StringReader(activator.asXML())); } catch (Exception cnfe) { throw new XmlException(cnfe); } intToActivatorMap.put(activators, activatorObject); activators++; } } } // now that we've built a cross-reference of index-to-neuron // we can process the synapses and easily reconstruct // the connections between neurons Integer inputIndex = 0, outputIndex, activatorIndex = 0; Double weight; for (Object e : root.elements()) if (((Element) e).getName().compareTo("layers") == 0) { for (Object layerObject : current.elements()) if (((Element) layerObject).getName().compareTo("layer") == 0) { for (Object neuronObject : ((Element) layerObject).elements()) if (((Element) neuronObject).getName().compareTo("neuron") == 0) { current = (Element) neuronObject; neuron = intToNeuronMap.get(inputIndex); // set the activator attr = current.attribute("activator-index"); activatorIndex = Integer.valueOf(attr.getValue()); neuron.setActivator(intToActivatorMap.get(activatorIndex)); // process the out-going synapses of the neuron if (current.element("synapses") != null && current.element("synapses").element("synapse") != null) { for (Object e2 : current.element("synapses").elements()) if (e2 instanceof Element) { current = (Element) e2; // get the synapses output neuron attr = current.attribute("output"); outputIndex = Integer.valueOf(attr.getValue()); outputNeuron = intToNeuronMap.get(outputIndex); // set the weight of the synapse attr = current.attribute("weight"); weight = Double.valueOf(attr.getValue()); Synapse s = new GenericSynapse(); neuron.setSynapseTo(s, outputNeuron); s.setWeight(weight); } } inputIndex++; } } } obj.getInputNeurons().clear(); obj.getOutputNeurons().clear(); obj.getInputNeurons().addAll(obj.getAllLayers().get(0)); obj.getOutputNeurons().addAll(obj.getAllLayers().get(obj.getAllLayers().size() - 1)); }
From source file:com.jswiff.xml.ActionXMLReader.java
License:Open Source License
static Action readAction(Element element) { String name = element.getName(); Action action;//from w w w . j av a2 s . co m if (name.equals("add")) { action = new Add(); } else if (name.equals("add2")) { action = new Add2(); } else if (name.equals("and")) { action = new And(); } else if (name.equals("asciitochar")) { action = new AsciiToChar(); } else if (name.equals("bitand")) { action = new BitAnd(); } else if (name.equals("bitlshift")) { action = new BitLShift(); } else if (name.equals("bitor")) { action = new BitOr(); } else if (name.equals("bitrshift")) { action = new BitRShift(); } else if (name.equals("biturshift")) { action = new BitURShift(); } else if (name.equals("bitxor")) { action = new BitXor(); } else if (name.equals("call")) { action = new Call(); } else if (name.equals("callfunction")) { action = new CallFunction(); } else if (name.equals("callmethod")) { action = new CallMethod(); } else if (name.equals("castop")) { action = new CastOp(); } else if (name.equals("chartoascii")) { action = new CharToAscii(); } else if (name.equals("clonesprite")) { action = new CloneSprite(); } else if (name.equals("constantpool")) { action = readConstantPool(element); } else if (name.equals("decrement")) { action = new Decrement(); } else if (name.equals("definefunction")) { action = readDefineFunction(element); } else if (name.equals("definefunction2")) { action = readDefineFunction2(element); } else if (name.equals("definelocal")) { action = new DefineLocal(); } else if (name.equals("definelocal2")) { action = new DefineLocal2(); } else if (name.equals("delete")) { action = new Delete(); } else if (name.equals("delete2")) { action = new Delete2(); } else if (name.equals("divide")) { action = new Divide(); } else if (name.equals("enddrag")) { action = new EndDrag(); } else if (name.equals("enumerate")) { action = new Enumerate(); } else if (name.equals("enumerate2")) { action = new Enumerate2(); } else if (name.equals("equals")) { action = new Equals(); } else if (name.equals("equals2")) { action = new Equals2(); } else if (name.equals("extends")) { action = new Extends(); } else if (name.equals("getmember")) { action = new GetMember(); } else if (name.equals("getproperty")) { action = new GetProperty(); } else if (name.equals("gettime")) { action = new GetTime(); } else if (name.equals("geturl")) { action = readGetURL(element); } else if (name.equals("geturl2")) { action = readGetURL2(element); } else if (name.equals("getvariable")) { action = new GetVariable(); } else if (name.equals("gotoframe")) { action = readGoToFrame(element); } else if (name.equals("gotoframe2")) { action = readGoToFrame2(element); } else if (name.equals("gotolabel")) { action = readGoToLabel(element); } else if (name.equals("greater")) { action = new Greater(); } else if (name.equals("if")) { action = readIf(element); } else if (name.equals("implementsop")) { action = new ImplementsOp(); } else if (name.equals("increment")) { action = new Increment(); } else if (name.equals("initarray")) { action = new InitArray(); } else if (name.equals("initobject")) { action = new InitObject(); } else if (name.equals("instanceof")) { action = new InstanceOf(); } else if (name.equals("jump")) { action = readJump(element); } else if (name.equals("less")) { action = new Less(); } else if (name.equals("less2")) { action = new Less2(); } else if (name.equals("mbasciitochar")) { action = new MBAsciiToChar(); } else if (name.equals("mbchartoascii")) { action = new MBCharToAscii(); } else if (name.equals("mbstringextract")) { action = new MBStringExtract(); } else if (name.equals("mbstringlength")) { action = new MBStringLength(); } else if (name.equals("modulo")) { action = new Modulo(); } else if (name.equals("multiply")) { action = new Multiply(); } else if (name.equals("newmethod")) { action = new NewMethod(); } else if (name.equals("newobject")) { action = new NewObject(); } else if (name.equals("nextframe")) { action = new NextFrame(); } else if (name.equals("not")) { action = new Not(); } else if (name.equals("or")) { action = new Or(); } else if (name.equals("play")) { action = new Play(); } else if (name.equals("pop")) { action = new Pop(); } else if (name.equals("previousframe")) { action = new PreviousFrame(); } else if (name.equals("push")) { action = readPush(element); } else if (name.equals("pushduplicate")) { action = new PushDuplicate(); } else if (name.equals("randomnumber")) { action = new RandomNumber(); } else if (name.equals("removesprite")) { action = new RemoveSprite(); } else if (name.equals("return")) { action = new Return(); } else if (name.equals("setmember")) { action = new SetMember(); } else if (name.equals("setproperty")) { action = new SetProperty(); } else if (name.equals("settarget")) { action = readSetTarget(element); } else if (name.equals("settarget2")) { action = new SetTarget2(); } else if (name.equals("setvariable")) { action = new SetVariable(); } else if (name.equals("stackswap")) { action = new StackSwap(); } else if (name.equals("startdrag")) { action = new StartDrag(); } else if (name.equals("stop")) { action = new Stop(); } else if (name.equals("stopsounds")) { action = new StopSounds(); } else if (name.equals("storeregister")) { action = readStoreRegister(element); } else if (name.equals("strictequals")) { action = new StrictEquals(); } else if (name.equals("stringadd")) { action = new StringAdd(); } else if (name.equals("stringequals")) { action = new StringEquals(); } else if (name.equals("stringextract")) { action = new StringExtract(); } else if (name.equals("stringgreater")) { action = new StringGreater(); } else if (name.equals("stringlength")) { action = new StringLength(); } else if (name.equals("stringless")) { action = new StringLess(); } else if (name.equals("subtract")) { action = new Subtract(); } else if (name.equals("targetpath")) { action = new TargetPath(); } else if (name.equals("throw")) { action = new Throw(); } else if (name.equals("tointeger")) { action = new ToInteger(); } else if (name.equals("tonumber")) { action = new ToNumber(); } else if (name.equals("tostring")) { action = new ToString(); } else if (name.equals("togglequality")) { action = new ToggleQuality(); } else if (name.equals("trace")) { action = new Trace(); } else if (name.equals("try")) { action = readTry(element); } else if (name.equals("typeof")) { action = new TypeOf(); } else if (name.equals("waitforframe")) { action = readWaitForFrame(element); } else if (name.equals("waitforframe2")) { action = readWaitForFrame2(element); } else if (name.equals("with")) { action = readWith(element); } else if (name.equals("unknownaction")) { action = readUnknownAction(element); } else { throw new IllegalArgumentException("Unexpected action record name: " + name); } Attribute label = element.attribute("label"); if (label != null) { action.setLabel(label.getValue()); } return action; }
From source file:com.jswiff.xml.ActionXMLReader.java
License:Open Source License
private static Try readTry(Element element) { Try tryAction;/*from ww w. java 2 s .co m*/ Attribute catchRegister = element.attribute("catchregister"); if (catchRegister != null) { tryAction = new Try(Short.parseShort(catchRegister.getValue())); } else { Attribute catchVariable = element.attribute("catchvariable"); if (catchVariable != null) { tryAction = new Try(catchVariable.getValue()); } else { throw new MissingNodeException( "Neither catch register nor catch variable specified within try action!"); } } RecordXMLReader.readActionBlock(tryAction.getTryBlock(), RecordXMLReader.getElement("try", element)); Element catchElement = element.element("catch"); if (catchElement != null) { RecordXMLReader.readActionBlock(tryAction.getCatchBlock(), catchElement); } Element finallyElement = element.element("finally"); if (finallyElement != null) { RecordXMLReader.readActionBlock(tryAction.getFinallyBlock(), finallyElement); } return tryAction; }
From source file:com.jswiff.xml.RecordXMLReader.java
License:Open Source License
static boolean getBooleanAttribute(String name, Element parentElement) { // boolean attributes are written only for "true" values Attribute attribute = parentElement.attribute(name); return ((attribute != null) && attribute.getValue().equalsIgnoreCase("true")); }
From source file:com.jswiff.xml.RecordXMLReader.java
License:Open Source License
static String getStringAttribute(String attributeName, Element parentElement) { Attribute attribute = parentElement.attribute(attributeName); if (attribute == null) { throw new MissingAttributeException(attributeName, parentElement.getPath()); }/*ww w .ja v a 2s .com*/ return attribute.getValue(); }