use of org.jdom.Namespace in project vcell by virtualcell.
the class MicroscopyXmlReader method getAnnotatedImageDataset.
public AnnotatedImageDataset getAnnotatedImageDataset(Element param, /*root, frapstudy element*/
ClientTaskStatusSupport progressListener) throws XmlParseException {
// get frapData element
Element frapDataElement = param.getChild(MicroscopyXMLTags.FRAPDataTag);
Element imageDatasetElement = frapDataElement.getChild(MicroscopyXMLTags.ImageDatasetTag);
ImageDataset imageDataset = null;
if (imageDatasetElement != null) {
imageDataset = getImageDataset(imageDatasetElement, progressListener);
}
Namespace ns = param.getNamespace();
List<Element> roiList = frapDataElement.getChildren(MicroscopyXMLTags.ROITag);
ROI[] rois = new ROI[0];
int numROIs = roiList.size();
if (numROIs > 0) {
rois = new ROI[numROIs];
Iterator<Element> roiIter = roiList.iterator();
int index = 0;
while (roiIter.hasNext()) {
Element roiElement = roiIter.next();
rois[index++] = getROI(roiElement);
}
}
// reorder ROIs according to the order of FRAPData.VFRAP_ROI_ENUM
ROI[] reorderedROIs = AnnotatedImageDataset.reorderROIs(rois);
AnnotatedImageDataset annotatedImages = new AnnotatedImageDataset(imageDataset, reorderedROIs);
// After loading all the ROI rings, the progress should set to 100.
if (progressListener != null) {
progressListener.setProgress(100);
}
return annotatedImages;
}
use of org.jdom.Namespace in project che by eclipse.
the class EffectivePomWriter method addMavenNamespace.
/**
* method from org.apache.maven.plugins.help.AbstractEffectiveMojo
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.Namespace in project intellij-plugins by JetBrains.
the class FlexCompilerConfigFileUtilBase method makeLibrariesMergedIntoCode.
private static void makeLibrariesMergedIntoCode(final Element rootElement, final boolean externalLibs, final boolean includedLibs) {
final Namespace namespace = rootElement.getNamespace();
final Collection<String> paths = removeLibs(rootElement, externalLibs, includedLibs);
if (!paths.isEmpty()) {
final Element compilerElement = rootElement.getChild(COMPILER, namespace);
Element libraryPathElement = compilerElement.getChild(LIBRARY_PATH, namespace);
if (libraryPathElement == null) {
libraryPathElement = new Element(LIBRARY_PATH, namespace);
libraryPathElement.setAttribute(new Attribute(APPEND, "true"));
compilerElement.addContent(libraryPathElement);
}
for (final String path : paths) {
final Element pathElement = new Element(PATH_ELEMENT, namespace);
pathElement.addContent(path);
libraryPathElement.addContent(pathElement);
}
}
}
use of org.jdom.Namespace in project maven-plugins by apache.
the class AbstractEffectiveMojo method addMavenNamespace.
/**
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.Namespace in project vcell by virtualcell.
the class XmlHelper method XMLToBioModel.
static BioModel XMLToBioModel(XMLSource xmlSource, boolean printkeys, ModelUnitSystem forcedModelUnitSystem) throws XmlParseException {
// long l0 = System.currentTimeMillis();
BioModel bioModel = null;
if (xmlSource == null) {
throw new XmlParseException("Invalid xml for Biomodel.");
}
Document xmlDoc = xmlSource.getXmlDoc();
// NOTES:
// * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
// * With the old-style vcml, the namespace was " "
// * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
// was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
// "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
// <biomdel>, etc. was " "
// * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
// for <vcml> and all children elements.
// The code below attempts to take care of this situation.
Element root = xmlDoc.getRootElement();
Namespace ns = null;
if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
// NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
ns = root.getNamespace();
Element bioRoot = root.getChild(XMLTags.BioModelTag, ns);
if (bioRoot == null) {
bioRoot = root.getChild(XMLTags.BioModelTag);
// bioRoot was null, so obtained the <Biomodel> element with namespace " ";
// Re-set the namespace so that the correct XMLReader constructor is invoked.
ns = null;
}
root = bioRoot;
}
// else - root is assumed to be old-style vcml with <Biomodel> as root.
// common for both new way (with xml declaration, vcml element, etc) and existing way (biomodel is root)
// If namespace is null, xml is the old-style xml with biomodel as root, so invoke XMLReader without namespace argument.
XmlReader reader = null;
VCellSoftwareVersion vCellSoftwareVersion = null;
if (ns == null) {
reader = new XmlReader(printkeys);
} else {
reader = new XmlReader(printkeys, ns);
vCellSoftwareVersion = VCellSoftwareVersion.fromString(root.getAttributeValue(XMLTags.SoftwareVersionAttrTag, ns));
}
if (forcedModelUnitSystem != null) {
reader.setForcedModelUnitSystem(forcedModelUnitSystem);
}
bioModel = reader.getBioModel(root, vCellSoftwareVersion);
// long l1 = System.currentTimeMillis();
bioModel.refreshDependencies();
return bioModel;
}
Aggregations