use of org.jdom.Namespace in project vcell by virtualcell.
the class XMLDict method getMatchingElement.
private static Element getMatchingElement(Element root, String reName, String attName, String attValue) {
String path;
// accomodate math models.
if (!root.getName().equals(XMLTags.MathModelTag)) {
path = (String) reHashBio.get(reName);
} else {
path = (String) reHashMath.get(reName);
}
if (path == null) {
System.err.println("The xpath of the element to resolve is not available: " + reName);
return getMatchingElementGeneric(root, reName, attName, attValue);
}
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(path, XMLDict.XPATH_SEP);
// System.out.println(root.getName() + " " + reName + " " + attName + " " + attValue + " " + path + " " + tokenizer.countTokens());
if (tokenizer.countTokens() < 2) {
// the element to resolve is the root. Should not happen.
System.err.println("No tokens found for element: " + reName);
return null;
}
while (tokenizer.hasMoreTokens()) {
// start at the parent of interest, which can be a shorter path than the one saved.
String curToken = tokenizer.nextToken();
if (root.getName().equals(curToken)) {
break;
}
}
Namespace ns = root.getNamespace();
for (int i = 0; i < tokenizer.countTokens() - 1; i++) {
// break when reaching the direct parent.
String elementName = tokenizer.nextToken();
// System.out.println("Current Token: " + elementName);
root = root.getChild(elementName, ns);
}
String resElementName = tokenizer.nextToken();
// System.out.println(resElementName);
@SuppressWarnings("unchecked") Iterator<Element> // last 2 tokens (direct parent, and element to resolve)
iterator = root.getChildren(resElementName, ns).iterator();
Element temp = null;
while (iterator.hasNext()) {
temp = iterator.next();
if (attValue.equals(temp.getAttributeValue(attName))) {
break;
} else {
temp = null;
}
}
return temp;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class DataBaseReferenceReader method getReferenceFromUniProt.
private static String getReferenceFromUniProt(String moleculeID, String dbFormat, String dbStyle) throws ServiceException, DbfConnException, DbfNoEntryFoundException, DbfParamsException, DbfException, InputException, RemoteException {
String referenceName = null;
String xmlStr = getXMLFromUniProt(moleculeID, dbFormat, dbStyle);
// get root
Element uniprotRoot = XmlUtil.stringToXML(xmlStr, null).getRootElement();
Namespace uniprotNameSpace = uniprotRoot.getNamespace();
// get entry
Element entryElement = uniprotRoot.getChild(UniProt_EntryTag, uniprotNameSpace);
// get name
if (entryElement == null) {
// not a big deal if we cannot get the uniprot name
return null;
}
Element nameElement = entryElement.getChild(Uniprot_NameTag, uniprotNameSpace);
if (nameElement == null) {
return null;
}
referenceName = nameElement.getText();
return referenceName;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class DataBaseReferenceReader method getReferenceFromInterpro.
private static String getReferenceFromInterpro(String dbName, String moleculeID, String dbFormat, String dbStyle) throws ServiceException, DbfConnException, DbfNoEntryFoundException, DbfParamsException, DbfException, InputException, RemoteException {
String referenceName = null;
String xmlStr = getXMLFromInterpro(dbName, moleculeID, dbFormat, dbStyle);
// get root
Element root = XmlUtil.stringToXML(xmlStr, null).getRootElement();
Namespace nameSpace = root.getNamespace();
// get entry
Element entryElement = root.getChild(Interpro_EntryTag, nameSpace);
// get name
if (entryElement == null) {
// not a big deal if we cannot get the interpro name
return null;
}
Element nameElement = entryElement.getChild(Interpro_NameTag, nameSpace);
if (nameElement == null) {
return null;
}
referenceName = nameElement.getText();
return referenceName;
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class PathwayReaderBiopax3 method addObjectBiochemicalReaction.
private BiochemicalReaction addObjectBiochemicalReaction(Element element) {
Namespace bp = Namespace.getNamespace("bp", "http://www.biopax.org/release/biopax-level3.owl#");
if (element.getChild("TransportWithBiochemicalReaction", bp) != null) {
return addObjectTransportWithBiochemicalReaction(element.getChild("TransportWithBiochemicalReaction", bp));
}
BiochemicalReaction biochemicalReaction = new BiochemicalReactionImpl();
addAttributes(biochemicalReaction, element);
for (Object child : element.getChildren()) {
if (child instanceof Element) {
Element childElement = (Element) child;
if (!addContentBiochemicalReaction(biochemicalReaction, element, childElement)) {
showUnexpected(childElement);
}
}
}
pathwayModel.add(biochemicalReaction);
return biochemicalReaction;
}
use of org.jdom.Namespace in project cxf by apache.
the class StaxSerializer method writeElement.
public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
// need to check if the namespace is declared before we write the
// start element because that will put the namespace in the context.
String elPrefix = e.getNamespacePrefix();
String elUri = e.getNamespaceURI();
String boundPrefix = writer.getPrefix(elUri);
boolean writeElementNS = false;
if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
writeElementNS = true;
}
writer.writeStartElement(elPrefix, e.getName(), elUri);
List<?> namespaces = e.getAdditionalNamespaces();
for (Iterator<?> itr = namespaces.iterator(); itr.hasNext(); ) {
Namespace ns = (Namespace) itr.next();
String prefix = ns.getPrefix();
String uri = ns.getURI();
writer.setPrefix(prefix, uri);
writer.writeNamespace(prefix, uri);
if (elUri.equals(uri) && elPrefix.equals(prefix)) {
writeElementNS = false;
}
}
for (Iterator<?> itr = e.getAttributes().iterator(); itr.hasNext(); ) {
Attribute attr = (Attribute) itr.next();
String attPrefix = attr.getNamespacePrefix();
String attUri = attr.getNamespaceURI();
if (attUri == null || attUri.isEmpty()) {
writer.writeAttribute(attr.getName(), attr.getValue());
} else {
writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());
if (!isDeclared(writer, attPrefix, attUri)) {
if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
if (writeElementNS) {
writer.setPrefix(attPrefix, attUri);
writer.writeNamespace(attPrefix, attUri);
writeElementNS = false;
}
} else {
writer.setPrefix(attPrefix, attUri);
writer.writeNamespace(attPrefix, attUri);
}
}
}
}
if (writeElementNS) {
if (elPrefix == null || elPrefix.length() == 0) {
writer.writeDefaultNamespace(elUri);
} else {
writer.writeNamespace(elPrefix, elUri);
}
}
for (Iterator<?> itr = e.getContent().iterator(); itr.hasNext(); ) {
Content n = (Content) itr.next();
if (n instanceof CDATA) {
writer.writeCData(n.getValue());
} else if (n instanceof Text) {
writer.writeCharacters(((Text) n).getText());
} else if (n instanceof Element) {
writeElement((Element) n, writer);
} else if (n instanceof Comment) {
writer.writeComment(n.getValue());
} else if (n instanceof EntityRef) {
// EntityRef ref = (EntityRef) n;
// writer.writeEntityRef(ref.)
}
}
writer.writeEndElement();
}
Aggregations