Search in sources :

Example 96 with Namespace

use of org.jdom.Namespace in project cxf by apache.

the class JDOMStreamReader method setupNamespaces.

private void setupNamespaces(Element element) {
    namespaceContext.setElement(element);
    if (prefix2decNs != null) {
        namespaceStack.push(prefix2decNs);
    }
    prefix2decNs = new HashMap<>();
    namespaces.clear();
    for (Iterator<?> itr = element.getAdditionalNamespaces().iterator(); itr.hasNext(); ) {
        declare((Namespace) itr.next());
    }
    Namespace ns = element.getNamespace();
    if (shouldDeclare(ns)) {
        declare(ns);
    }
    for (Iterator<?> itr = element.getAttributes().iterator(); itr.hasNext(); ) {
        ns = ((Attribute) itr.next()).getNamespace();
        if (shouldDeclare(ns)) {
            declare(ns);
        }
    }
}
Also used : Namespace(org.jdom.Namespace)

Example 97 with Namespace

use of org.jdom.Namespace in project cxf by apache.

the class JDOMStreamReader method getDeclaredURI.

private String getDeclaredURI(String string) {
    for (int i = namespaceStack.size() - 1; i == 0; i--) {
        Map<String, Namespace> nmspaces = namespaceStack.get(i);
        Namespace dec = nmspaces.get(string);
        if (dec != null) {
            return dec.getURI();
        }
    }
    return null;
}
Also used : Namespace(org.jdom.Namespace)

Example 98 with Namespace

use of org.jdom.Namespace in project cxf by apache.

the class StaxBuilder method buildTree.

/**
 * This takes a <code>XMLStreamReader</code> and builds up a JDOM tree.
 * Recursion has been eliminated by using local stack of open elements; this
 * improves performance somewhat (classic
 * recursion-by-iteration-and-explicit stack transformation)
 *
 * @param node <code>Code</node> to examine.
 * @param doc JDOM <code>Document</code> being built.
 */
private void buildTree(JDOMFactory f, XMLStreamReader r, Document doc) throws XMLStreamException {
    // At top level
    Element current = null;
    int event = r.getEventType();
    // if we're at the start then we need to do a next
    if (event == -1) {
        event = r.next();
    }
    while (true) {
        boolean noadd = false;
        Content child = null;
        switch(event) {
            case XMLStreamConstants.CDATA:
                child = f.cdata(r.getText());
                break;
            case XMLStreamConstants.SPACE:
                if (cfgIgnoreWS) {
                    noadd = true;
                    break;
                }
            case XMLStreamConstants.CHARACTERS:
                /*
                 * Small complication: although (ignorable) white space is
                 * allowed in prolog/epilog, and StAX may report such event,
                 * JDOM barfs if trying to add it. Thus, let's just ignore all
                 * textual stuff outside the tree:
                 */
                if (current == null) {
                    noadd = true;
                    break;
                }
                child = f.text(r.getText());
                break;
            case XMLStreamConstants.COMMENT:
                child = f.comment(r.getText());
                break;
            case XMLStreamConstants.END_DOCUMENT:
                return;
            case XMLStreamConstants.END_ELEMENT:
                /**
                 * If current.getParentElement() previously returned null and we
                 * get this event again we shouldn't bail out with a
                 * NullPointerException
                 */
                if (current != null) {
                    current = current.getParentElement();
                }
                noadd = true;
                if (isReadingMidStream && current == null)
                    return;
                break;
            case XMLStreamConstants.ENTITY_DECLARATION:
            case XMLStreamConstants.NOTATION_DECLARATION:
                /*
                 * Shouldn't really get these, but maybe some stream readers do
                 * provide the info. If so, better ignore it -- DTD event should
                 * have most/all we need.
                 */
                noadd = true;
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                child = f.entityRef(r.getLocalName());
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                child = f.processingInstruction(r.getPITarget(), r.getPIData());
                break;
            case XMLStreamConstants.START_ELEMENT:
                {
                    // Ok, need to add a new element and simulate recursion
                    Element newElem = null;
                    String nsURI = r.getNamespaceURI();
                    // needed for special
                    String elemPrefix = r.getPrefix();
                    // handling of elem's
                    // namespace
                    String ln = r.getLocalName();
                    if (nsURI == null || nsURI.length() == 0) {
                        if (elemPrefix == null || elemPrefix.length() == 0) {
                            newElem = f.element(ln);
                        } else {
                            /*
                         * Happens when a prefix is bound to the default (empty)
                         * namespace...
                         */
                            newElem = f.element(ln, elemPrefix, "");
                        }
                    } else {
                        newElem = f.element(ln, elemPrefix, nsURI);
                    }
                    /*
                 * Let's add element right away (probably have to do it to bind
                 * attribute namespaces, too)
                 */
                    if (current == null) {
                        // at root
                        doc.setRootElement(newElem);
                        if (additionalNamespaces != null) {
                            for (Iterator<String> iter = additionalNamespaces.keySet().iterator(); iter.hasNext(); ) {
                                String prefix = iter.next();
                                String uri = additionalNamespaces.get(prefix);
                                newElem.addNamespaceDeclaration(Namespace.getNamespace(prefix, uri));
                            }
                        }
                    } else {
                        f.addContent(current, newElem);
                    }
                    // Any declared namespaces?
                    int i;
                    int len;
                    for (i = 0, len = r.getNamespaceCount(); i < len; ++i) {
                        String prefix = r.getNamespacePrefix(i);
                        Namespace ns = Namespace.getNamespace(prefix, r.getNamespaceURI(i));
                        // JDOM has special handling for element's "own" ns:
                        if (prefix != null && prefix.equals(elemPrefix)) {
                        // already set by when it was constructed...
                        } else {
                            f.addNamespaceDeclaration(newElem, ns);
                        }
                    }
                    // And then the attributes:
                    for (i = 0, len = r.getAttributeCount(); i < len; ++i) {
                        String prefix = r.getAttributePrefix(i);
                        Namespace ns;
                        if (prefix == null || prefix.length() == 0) {
                            // Attribute not in any namespace
                            ns = Namespace.NO_NAMESPACE;
                        } else {
                            ns = newElem.getNamespace(prefix);
                        }
                        Attribute attr = f.attribute(r.getAttributeLocalName(i), r.getAttributeValue(i), resolveAttrType(r.getAttributeType(i)), ns);
                        f.setAttribute(newElem, attr);
                    }
                    // And then 'push' new element...
                    current = newElem;
                    // Already added the element, can continue
                    noadd = true;
                    break;
                }
            case XMLStreamConstants.START_DOCUMENT:
            case XMLStreamConstants.DTD:
            // case XMLStreamConstants.NAMESPACE:
            default:
                /*
                 * throw new XMLStreamException("Unrecognized iterator event
                 * type: " + r.getEventType() + "; should not receive such types
                 * (broken stream reader?)");
                 */
                break;
        }
        if (!noadd && child != null) {
            if (current == null) {
                f.addContent(doc, child);
            } else {
                f.addContent(current, child);
            }
        }
        if (r.hasNext()) {
            event = r.next();
        } else {
            break;
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Content(org.jdom.Content) Element(org.jdom.Element) Iterator(java.util.Iterator) Namespace(org.jdom.Namespace)

Example 99 with Namespace

use of org.jdom.Namespace in project vcell by virtualcell.

the class MicroscopyXmlReader method getPrimaryROIs.

/**
 * This method is only called by DataSymbolsPanel to get the primary ROIs
 */
public ROI[] getPrimaryROIs(Element param, /*root, frapstudy element*/
ClientTaskStatusSupport progressListener) throws XmlParseException {
    // get frapData element
    Element frapDataElement = param.getChild(MicroscopyXMLTags.FRAPDataTag);
    Namespace ns = param.getNamespace();
    List<Element> roiList = frapDataElement.getChildren(MicroscopyXMLTags.ROITag);
    ROI[] rois = null;
    int numROIs = 3;
    if (numROIs > 0) {
        rois = new ROI[numROIs];
        Iterator<Element> roiIter = roiList.iterator();
        int index = 0;
        while (roiIter.hasNext()) {
            Element roiElement = roiIter.next();
            if (roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BLEACHED.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_CELL.name())) {
                rois[index++] = getROI(roiElement);
                if (index == 3) {
                    break;
                }
            }
        }
    }
    // reorder ROIs according to the order of FRAPData.VFRAP_ROI_ENUM
    ROI[] reorderedROIs = AnnotatedImageDataset.reorderROIs(rois);
    return reorderedROIs;
}
Also used : Element(org.jdom.Element) ROI(cbit.vcell.VirtualMicroscopy.ROI) Namespace(org.jdom.Namespace)

Example 100 with Namespace

use of org.jdom.Namespace in project build-info by JFrogDev.

the class PomTransformer method transform.

/**
 * Performs the transformation.
 *
 * @return True if the file was modified.
 */
public Boolean transform(File pomFile) throws IOException {
    this.pomFile = pomFile;
    if (!pomFile.exists()) {
        throw new IllegalArgumentException("Couldn't find pom file: " + pomFile);
    }
    SAXBuilder saxBuilder = createSaxBuilder();
    Document document;
    EolDetectingInputStream eolDetectingStream = null;
    InputStreamReader inputStreamReader = null;
    try {
        eolDetectingStream = new EolDetectingInputStream(new FileInputStream(pomFile));
        inputStreamReader = new InputStreamReader(eolDetectingStream, "UTF-8");
        document = saxBuilder.build(inputStreamReader);
    } catch (JDOMException e) {
        throw new IOException("Failed to parse pom: " + pomFile.getAbsolutePath(), e);
    } finally {
        IOUtils.closeQuietly(inputStreamReader);
        IOUtils.closeQuietly(eolDetectingStream);
    }
    Element rootElement = document.getRootElement();
    Namespace ns = rootElement.getNamespace();
    getProperties(rootElement, ns);
    changeParentVersion(rootElement, ns);
    changeCurrentModuleVersion(rootElement, ns);
    // changePropertiesVersion(rootElement, ns);
    changeDependencyManagementVersions(rootElement, ns);
    changeDependencyVersions(rootElement, ns);
    if (scmUrl != null) {
        changeScm(rootElement, ns);
    }
    if (modified && !dryRun) {
        FileOutputStream fileOutputStream = new FileOutputStream(pomFile);
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8");
        try {
            XMLOutputter outputter = new XMLOutputter();
            String eol = eolDetectingStream.getEol();
            if (!"".equals(eol)) {
                Format format = outputter.getFormat();
                format.setLineSeparator(eol);
                format.setTextMode(Format.TextMode.PRESERVE);
                outputter.setFormat(format);
            }
            outputter.output(document, outputStreamWriter);
        } finally {
            IOUtils.closeQuietly(outputStreamWriter);
            IOUtils.closeQuietly(fileOutputStream);
        }
    }
    return modified;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) Namespace(org.jdom.Namespace) Format(org.jdom.output.Format) EolDetectingInputStream(org.jfrog.build.extractor.EolDetectingInputStream)

Aggregations

Namespace (org.jdom.Namespace)102 Element (org.jdom.Element)85 IOException (java.io.IOException)24 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)15 Configuration (org.apache.hadoop.conf.Configuration)15 JDOMException (org.jdom.JDOMException)15 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)13 ArrayList (java.util.ArrayList)12 Path (org.apache.hadoop.fs.Path)11 Document (org.jdom.Document)11 List (java.util.List)9 File (java.io.File)7 HashMap (java.util.HashMap)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)6 SAXBuilder (org.jdom.input.SAXBuilder)6 XMLOutputter (org.jdom.output.XMLOutputter)6 Writer (java.io.Writer)5 Attribute (org.jdom.Attribute)5 Format (org.jdom.output.Format)5