Search in sources :

Example 16 with Namespace

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;
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Element(org.jdom.Element) ROI(cbit.vcell.VirtualMicroscopy.ROI) Namespace(org.jdom.Namespace)

Example 17 with Namespace

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. &lt;project/&gt; or &lt;settings/&gt; 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;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StringWriter(java.io.StringWriter) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 18 with Namespace

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);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 19 with Namespace

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. &lt;project/&gt; or &lt;settings/&gt; 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;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) Element(org.jdom.Element) ElementFilter(org.jdom.filter.ElementFilter) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace)

Example 20 with Namespace

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;
}
Also used : VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) BioModel(cbit.vcell.biomodel.BioModel) Element(org.jdom.Element) Document(org.jdom.Document) VCDocument(org.vcell.util.document.VCDocument) Namespace(org.jdom.Namespace)

Aggregations

Namespace (org.jdom.Namespace)35 Element (org.jdom.Element)32 Document (org.jdom.Document)7 IOException (java.io.IOException)5 VCDocument (org.vcell.util.document.VCDocument)5 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4 Geometry (cbit.vcell.geometry.Geometry)3 Attribute (org.jdom.Attribute)3 ROI (cbit.vcell.VirtualMicroscopy.ROI)2 BioModel (cbit.vcell.biomodel.BioModel)2 MathDescription (cbit.vcell.math.MathDescription)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 Simulation (cbit.vcell.solver.Simulation)2 StringWriter (java.io.StringWriter)2 Vector (java.util.Vector)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 Content (org.jdom.Content)2 JDOMException (org.jdom.JDOMException)2