Example usage for org.w3c.dom Element getParentNode

List of usage examples for org.w3c.dom Element getParentNode

Introduction

In this page you can find the example usage for org.w3c.dom Element getParentNode.

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:loci.formats.in.LIFReader.java

private void translateImageNames(Element imageNode, int image) {
    final List<String> names = new ArrayList<String>();
    Element parent = imageNode;
    while (true) {
        parent = (Element) parent.getParentNode();
        if (parent == null || parent.getNodeName().equals("LEICA")) {
            break;
        }/*from  ww  w  . java2 s  .  c o m*/
        if (parent.getNodeName().equals("Element")) {
            names.add(parent.getAttribute("Name"));
        }
    }
    imageNames[image] = "";
    for (int i = names.size() - 2; i >= 0; i--) {
        imageNames[image] += names.get(i);
        if (i > 0)
            imageNames[image] += "/";
    }
}

From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java

/** {@inheritDoc} */
public void moveInto(JavaSymbolName pageId, JavaSymbolName intoId) {
    Document document = getMenuDocument();

    // make the root element of the menu the one with the menu identifier
    // allowing for different decorations of menu
    Element rootElement = XmlUtils.findFirstElement(ID_MENU_EXP, (Element) document.getFirstChild());

    if (!rootElement.getNodeName().equals(GVNIX_MENU)) {
        throw new IllegalArgumentException(INVALID_XML);
    }//from   ww  w.j a v a  2  s .  c o m

    // check for existence of menu category by looking for the identifier
    // provided
    Element pageElement = XmlUtils.findFirstElement(ID_EXP.concat(pageId.getSymbolName()).concat("']"),
            rootElement);

    // exit if menu entry doesn't exist
    Validate.notNull(pageElement, PAGE.concat(pageId.getSymbolName()).concat(NOT_FOUND));

    Element intoElement = XmlUtils.findFirstElement(ID_EXP.concat(intoId.getSymbolName()).concat("']"),
            rootElement);

    // exit if menu entry doesn't exist
    Validate.notNull(intoElement, PAGE.concat(intoId.getSymbolName()).concat(NOT_FOUND));

    // parent element where remove menu entry element
    Element parent = (Element) pageElement.getParentNode();
    parent.removeChild(pageElement);

    // insert
    intoElement.appendChild(pageElement);

    writeXMLConfigIfNeeded(document);
}

From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java

/** {@inheritDoc} */
public void moveBefore(JavaSymbolName pageId, JavaSymbolName beforeId) {
    Document document = getMenuDocument();

    // make the root element of the menu the one with the menu identifier
    // allowing for different decorations of menu
    Element rootElement = XmlUtils.findFirstElement(ID_MENU_EXP, (Element) document.getFirstChild());

    if (!rootElement.getNodeName().equals(GVNIX_MENU)) {
        throw new IllegalArgumentException(INVALID_XML);
    }//  ww  w  .  j ava2 s .  c om

    // check for existence of menu category by looking for the identifier
    // provided
    Element pageElement = XmlUtils.findFirstElement(ID_EXP.concat(pageId.getSymbolName()).concat("']"),
            rootElement);

    // exit if menu entry doesn't exist
    Validate.notNull(pageElement, PAGE.concat(pageId.getSymbolName()).concat(NOT_FOUND));

    Element beforeElement = XmlUtils.findFirstElement(ID_EXP.concat(beforeId.getSymbolName()).concat("']"),
            rootElement);

    // exit if menu entry doesn't exist
    Validate.notNull(beforeElement, PAGE.concat(beforeId.getSymbolName()).concat(NOT_FOUND));

    // page parent element where remove menu entry element
    Element pageParentEl = (Element) pageElement.getParentNode();
    pageParentEl.removeChild(pageElement);

    // before parent element where execute insert before
    Element beforeParentEl = (Element) beforeElement.getParentNode();
    beforeParentEl.insertBefore(pageElement, beforeElement);

    writeXMLConfigIfNeeded(document);
}

From source file:loci.formats.in.LIFReader.java

private void translateMetadata(Element root) throws FormatException {
    Element realRoot = (Element) root.getChildNodes().item(0);

    NodeList toPrune = getNodes(realRoot, "LDM_Block_Sequential_Master");
    if (toPrune != null) {
        for (int i = 0; i < toPrune.getLength(); i++) {
            Element prune = (Element) toPrune.item(i);
            Element parent = (Element) prune.getParentNode();
            parent.removeChild(prune);//from   www  .  j a  v  a 2s .c om
        }
    }

    NodeList images = getNodes(realRoot, "Image");
    List<Element> imageNodes = new ArrayList<Element>();
    Long[] oldOffsets = null;
    if (images.getLength() > offsets.size()) {
        oldOffsets = offsets.toArray(new Long[offsets.size()]);
        offsets.clear();
    }

    int nextOffset = 0;
    for (int i = 0; i < images.getLength(); i++) {
        Element image = (Element) images.item(i);
        Element grandparent = (Element) image.getParentNode();
        if (grandparent == null) {
            continue;
        }
        grandparent = (Element) grandparent.getParentNode();
        if (grandparent == null) {
            continue;
        }
        if (!"ProcessingHistory".equals(grandparent.getNodeName())) {
            // image is being referenced from an event list
            imageNodes.add(image);
            if (oldOffsets != null && nextOffset < oldOffsets.length) {
                offsets.add(oldOffsets[nextOffset]);
            }
        }
        grandparent = (Element) grandparent.getParentNode();
        if (grandparent == null) {
            continue;
        }
        grandparent = (Element) grandparent.getParentNode();
        if (grandparent != null) {
            if (!"Image".equals(grandparent.getNodeName())) {
                nextOffset++;
            }
        }
    }

    tileCount = new int[imageNodes.size()];
    Arrays.fill(tileCount, 1);
    core = new ArrayList<CoreMetadata>(imageNodes.size());
    acquiredDate = new double[imageNodes.size()];
    descriptions = new String[imageNodes.size()];
    laserWavelength = new List[imageNodes.size()];
    laserIntensity = new List[imageNodes.size()];
    laserActive = new List[imageNodes.size()];
    laserFrap = new List[imageNodes.size()];
    timestamps = new double[imageNodes.size()][];
    activeDetector = new List[imageNodes.size()];
    serialNumber = new String[imageNodes.size()];
    lensNA = new Double[imageNodes.size()];
    magnification = new Double[imageNodes.size()];
    immersions = new String[imageNodes.size()];
    corrections = new String[imageNodes.size()];
    objectiveModels = new String[imageNodes.size()];
    posX = new Length[imageNodes.size()];
    posY = new Length[imageNodes.size()];
    posZ = new Length[imageNodes.size()];
    refractiveIndex = new Double[imageNodes.size()];
    cutIns = new List[imageNodes.size()];
    cutOuts = new List[imageNodes.size()];
    filterModels = new List[imageNodes.size()];
    microscopeModels = new String[imageNodes.size()];
    detectorModels = new List[imageNodes.size()];
    detectorIndexes = new HashMap[imageNodes.size()];
    zSteps = new Double[imageNodes.size()];
    tSteps = new Double[imageNodes.size()];
    pinholes = new Double[imageNodes.size()];
    zooms = new Double[imageNodes.size()];

    expTimes = new Double[imageNodes.size()][];
    gains = new Double[imageNodes.size()][];
    detectorOffsets = new Double[imageNodes.size()][];
    channelNames = new String[imageNodes.size()][];
    exWaves = new Double[imageNodes.size()][];
    imageROIs = new ROI[imageNodes.size()][];
    imageNames = new String[imageNodes.size()];

    core.clear();
    for (int i = 0; i < imageNodes.size(); i++) {
        Element image = imageNodes.get(i);

        CoreMetadata ms = new CoreMetadata();
        core.add(ms);

        int index = core.size() - 1;
        setSeries(index);

        translateImageNames(image, index);
        translateImageNodes(image, index);
        translateAttachmentNodes(image, index);
        translateScannerSettings(image, index);
        translateFilterSettings(image, index);
        translateTimestamps(image, index);
        translateLaserLines(image, index);
        translateROIs(image, index);
        translateSingleROIs(image, index);
        translateDetectors(image, index);

        final Deque<String> nameStack = new ArrayDeque<String>();
        populateOriginalMetadata(image, nameStack);
        addUserCommentMeta(image, i);
    }
    setSeries(0);

    int totalSeries = 0;
    for (int count : tileCount) {
        totalSeries += count;
    }
    ArrayList<CoreMetadata> newCore = new ArrayList<CoreMetadata>();
    for (int i = 0; i < core.size(); i++) {
        for (int tile = 0; tile < tileCount[i]; tile++) {
            newCore.add(core.get(i));
        }
    }
    core = newCore;
}

From source file:loci.formats.in.LIFReader.java

private void translateDetectors(Element imageNode, int image) throws FormatException {
    NodeList definitions = getNodes(imageNode, "ATLConfocalSettingDefinition");
    if (definitions == null)
        return;/*from  w w  w.  jav a2 s .co  m*/

    final List<String> channels = new ArrayList<String>();
    laserActive[image] = new ArrayList<Boolean>();
    int nextChannel = 0;
    for (int definition = 0; definition < definitions.getLength(); definition++) {
        Element definitionNode = (Element) definitions.item(definition);
        String parentName = definitionNode.getParentNode().getNodeName();
        boolean isMaster = parentName.endsWith("Master");
        NodeList detectors = getNodes(definitionNode, "Detector");
        if (detectors == null)
            return;
        int count = 0;
        for (int d = 0; d < detectors.getLength(); d++) {
            Element detector = (Element) detectors.item(d);
            NodeList multibands = null;
            if (!isMaster) {
                multibands = getNodes(definitionNode, "MultiBand");
            }

            String v = detector.getAttribute("Gain");
            Double gain = v == null || v.trim().isEmpty() ? null : new Double(v.trim());
            v = detector.getAttribute("Offset");
            Double offset = v == null || v.trim().isEmpty() ? null : new Double(v.trim());

            boolean active = "1".equals(detector.getAttribute("IsActive"));
            String c = detector.getAttribute("Channel");
            int channel = (c == null || c.trim().length() == 0) ? 0 : Integer.parseInt(c);
            if (active) {
                if (detectorIndexes[image] != null && detectorModels[image] != null) {
                    detectorModels[image].add(detectorIndexes[image].get(channel));
                }

                Element multiband = null;

                if (multibands != null) {
                    for (int i = 0; i < multibands.getLength(); i++) {
                        Element mb = (Element) multibands.item(i);
                        if (channel == Integer.parseInt(mb.getAttribute("Channel"))) {
                            multiband = mb;
                            break;
                        }
                    }
                }

                if (multiband != null) {
                    String dye = multiband.getAttribute("DyeName");
                    if (!channels.contains(dye)) {
                        channels.add(dye);
                    }

                    double cutIn = new Double(multiband.getAttribute("LeftWorld"));
                    double cutOut = new Double(multiband.getAttribute("RightWorld"));
                    if ((int) cutIn > 0) {
                        if (cutIns[image] == null) {
                            cutIns[image] = new ArrayList<PositiveFloat>();
                        }
                        Length in = FormatTools.getCutIn((double) Math.round(cutIn));
                        if (in != null) {
                            cutIns[image].add(in);
                        }
                    }
                    if ((int) cutOut > 0) {
                        if (cutOuts[image] == null) {
                            cutOuts[image] = new ArrayList<PositiveFloat>();
                        }
                        Length out = FormatTools.getCutOut((double) Math.round(cutOut));
                        if (out != null) {
                            cutOuts[image].add(out);
                        }
                    }
                } else {
                    channels.add("");
                }

                if (!isMaster) {
                    if (channel < nextChannel) {
                        nextChannel = 0;
                    }

                    if (nextChannel < getEffectiveSizeC()) {
                        if (gains[image] != null) {
                            gains[image][nextChannel] = gain;
                        }
                        if (detectorOffsets[image] != null) {
                            detectorOffsets[image][nextChannel] = offset;
                        }
                    }

                    nextChannel++;
                }
            } else {
                count++;
            }
            if (active && activeDetector[image] != null) {
                activeDetector[image].add(active);
            }
        }
        //Store values to check if actually it is active.
        if (!isMaster) {
            laserActive[image].add(count < detectors.getLength());
        }
    }

    if (channels != null && channelNames[image] != null) {
        for (int i = 0; i < getEffectiveSizeC(); i++) {
            int index = i + channels.size() - getEffectiveSizeC();
            if (index >= 0 && index < channels.size()) {
                if (channelNames[image][i] == null || channelNames[image][i].trim().isEmpty()) {
                    channelNames[image][i] = channels.get(index);
                }
            }
        }
    }
}

From source file:loci.formats.in.LIFReader.java

private void translateLaserLines(Element imageNode, int image) throws FormatException {
    NodeList aotfLists = getNodes(imageNode, "AotfList");
    if (aotfLists == null || aotfLists.getLength() == 0)
        return;// w ww. j a  v a2 s  . c  om

    laserWavelength[image] = new ArrayList<Double>();
    laserIntensity[image] = new ArrayList<Double>();
    laserFrap[image] = new ArrayList<Boolean>();

    int baseIntensityIndex = 0;

    for (int channel = 0; channel < aotfLists.getLength(); channel++) {
        Element aotf = (Element) aotfLists.item(channel);
        NodeList laserLines = getNodes(aotf, "LaserLineSetting");
        if (laserLines == null)
            return;
        String gpName = aotf.getParentNode().getParentNode().getNodeName();
        //might need parent for attachment
        boolean isMaster = gpName.endsWith("Sequential_Master") || gpName.endsWith("Attachment");
        laserFrap[image].add(gpName.endsWith("FRAP_Master"));
        for (int laser = 0; laser < laserLines.getLength(); laser++) {
            Element laserLine = (Element) laserLines.item(laser);

            if (isMaster) {
                continue;
            }
            String lineIndex = laserLine.getAttribute("LineIndex");
            String qual = laserLine.getAttribute("Qualifier");
            int index = lineIndex == null || lineIndex.trim().isEmpty() ? 0
                    : Integer.parseInt(lineIndex.trim());
            int qualifier = qual == null || qual.trim().isEmpty() ? 0 : Integer.parseInt(qual.trim());

            index += (2 - (qualifier / 10));
            if (index < 0) {
                continue;
                //index = 0;
            }

            String v = laserLine.getAttribute("LaserLine");
            Double wavelength = 0d;
            if (v != null && !v.trim().isEmpty()) {
                wavelength = new Double(v.trim());
            }
            if (index < laserWavelength[image].size()) {
                laserWavelength[image].set(index, wavelength);
            } else {
                for (int i = laserWavelength[image].size(); i < index; i++) {
                    laserWavelength[image].add(Double.valueOf(0));
                }
                laserWavelength[image].add(wavelength);
            }

            String intensity = laserLine.getAttribute("IntensityDev");
            double realIntensity = intensity == null || intensity.trim().isEmpty() ? 0d
                    : new Double(intensity.trim());
            realIntensity = 100d - realIntensity;

            int realIndex = baseIntensityIndex + index;

            if (realIndex < laserIntensity[image].size()) {
                laserIntensity[image].set(realIndex, realIntensity);
            } else {
                while (realIndex < laserIntensity[image].size()) {
                    laserIntensity[image].add(100d);
                }
                laserIntensity[image].add(realIntensity);
            }
        }

        baseIntensityIndex += laserWavelength[image].size();
    }
}

From source file:com.netscape.cmscore.apps.CMSEngine.java

/**
 * Parse server.xml to get the ports and IPs
 * @throws EBaseException/*  w  w w .  j a  va2 s .  com*/
 */
private void parseServerXML() throws EBaseException {
    try {
        String instanceRoot = mConfig.getString("instanceRoot");
        String path = instanceRoot + File.separator + "conf" + File.separator + SERVER_XML;
        DOMParser parser = new DOMParser();
        parser.parse(path);
        NodeList nodes = parser.getDocument().getElementsByTagName("Connector");
        String parentName = "";
        String name = "";
        String port = "";
        for (int i = 0; i < nodes.getLength(); i++) {
            Element n = (Element) nodes.item(i);

            parentName = "";
            Element p = (Element) n.getParentNode();
            if (p != null) {
                parentName = p.getAttribute("name");
            }
            name = n.getAttribute("name");
            port = n.getAttribute("port");

            // The "server.xml" file is parsed from top-to-bottom, and
            // supports BOTH "Port Separation" (the new default method)
            // as well as "Shared Ports" (the old legacy method).  Since
            // both methods must be supported, the file structure MUST
            // conform to ONE AND ONLY ONE of the following formats:
            //
            // Port Separation:
            //
            //  <Catalina>
            //     ...
            //     <!-- Port Separation:  Unsecure Port -->
            //     <Connector name="Unsecure" . . .
            //     ...
            //     <!-- Port Separation:  Agent Secure Port -->
            //     <Connector name="Agent" . . .
            //     ...
            //     <!-- Port Separation:  Admin Secure Port -->
            //     <Connector name="Admin" . . .
            //     ...
            //     <!-- Port Separation:  EE Secure Port -->
            //     <Connector name="EE" . . .
            //     ...
            //  </Catalina>
            //
            //
            // Shared Ports:
            //
            //  <Catalina>
            //     ...
            //     <!-- Shared Ports:  Unsecure Port -->
            //     <Connector name="Unsecure" . . .
            //     ...
            //     <!-- Shared Ports:  Agent, EE, and Admin Secure Port -->
            //     <Connector name="Secure" . . .
            //     ...
            //     <!--
            //     <Connector name="Unused" . . .
            //     -->
            //     ...
            //     <!--
            //     <Connector name="Unused" . . .
            //     -->
            //     ...
            //  </Catalina>
            //
            if (parentName.equals("Catalina")) {
                if (name.equals("Unsecure")) {
                    // Port Separation:  Unsecure Port
                    //                   OR
                    // Shared Ports:     Unsecure Port
                    info[EE_NON_SSL][PORT] = port;
                } else if (name.equals("Agent")) {
                    // Port Separation:  Agent Secure Port
                    info[AGENT][PORT] = port;
                } else if (name.equals("Admin")) {
                    // Port Separation:  Admin Secure Port
                    info[ADMIN][PORT] = port;
                } else if (name.equals("EE")) {
                    // Port Separation:  EE Secure Port
                    info[EE_SSL][PORT] = port;
                } else if (name.equals("EEClientAuth")) {
                    // Port Separation: EE Client Auth Secure Port
                    info[EE_CLIENT_AUTH_SSL][PORT] = port;
                } else if (name.equals("Secure")) {
                    // Shared Ports:  Agent, EE, and Admin Secure Port
                    info[AGENT][PORT] = port;
                    info[ADMIN][PORT] = port;
                    info[EE_SSL][PORT] = port;
                    info[EE_CLIENT_AUTH_SSL][PORT] = port;
                }
            }
        }

    } catch (Exception e) {
        logger.error("CMSEngine: parseServerXML exception: " + e.getMessage(), e);
        throw new EBaseException("CMSEngine: Cannot parse the configuration file. " + e.getMessage(), e);
    }
}

From source file:lcmc.data.VMSXML.java

/** Remove XML from some device. */
private void removeXML(final String domainName, final Map<String, String> parametersMap, final String path,
        final VirtualHardwareComparator vhc, final String virshOptions) {
    final String configName = namesConfigsMap.get(domainName);
    if (configName == null) {
        return;/*from  w  w w .  j  a  v a 2  s . co  m*/
    }
    final Node domainNode = getDomainNode(domainName);
    if (domainNode == null) {
        return;
    }
    final XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        final NodeList nodes = (NodeList) xpath.evaluate(path, domainNode, XPathConstants.NODESET);
        final Element hwNode = vhc.getElement(nodes, parametersMap);
        if (hwNode != null) {
            hwNode.getParentNode().removeChild(hwNode);
        }
    } catch (final javax.xml.xpath.XPathExpressionException e) {
        Tools.appError("could not evaluate: ", e);
        return;
    }
    saveAndDefine(domainNode, domainName, virshOptions);
}

From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java

/**
 * <p>//  w  ww .  ja  va 2s .  co  m
 * Adds a wsdl location to the codegen plugin configuration. If code
 * generation plugin configuration not exists, it will be created.
 * </p>
 * 
 * @param wsdlLocation WSDL file location.
 * @param wsdlDocument WSDL file.
 */
private void addExportWSDLLocationDocument(String wsdlLocation, Document wsdlDocument) {

    // install Plugin
    installWsdl2javaPlugin();

    // Get pom.xml
    String pomPath = getPomFilePath();
    Validate.notNull(pomPath, POM_FILE_NOT_FOUND);

    // Get a mutable pom.xml reference to modify it
    MutableFile pomMutableFile = getFileManager().updateFile(pomPath);
    Document pom = getInputDocument(pomMutableFile.getInputStream());
    Element root = pom.getDocumentElement();

    // Get plugin element
    Element codegenWsPlugin = XmlUtils.findFirstElement(
            "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-codegen-plugin']",
            root);

    // If plugin element not exists, error message
    Validate.notNull(codegenWsPlugin,
            "Codegen plugin is not defined in the pom.xml, relaunch again this command.");

    // Checks if already exists the execution.
    Element oldGenerateSourcesCxfServer = XmlUtils.findFirstElement(
            "/project/build/plugins/plugin/executions/execution[id='" + CXF_WSDL2JAVA_EXECUTION_ID + "']",
            root);

    // Generate execution configuration element.
    Element newGenerateSourcesCxfServer = createWsdl2JavaExecutionElement(pom, wsdlDocument, wsdlLocation);

    // Checks if exists executions.
    Element oldExecutions = DomUtils.findFirstElementByName(EXECUTIONS, codegenWsPlugin);

    Element newExecutions;

    // To Update execution definitions It must be replaced in pom.xml to
    // maintain the format.
    if (oldGenerateSourcesCxfServer != null) {
        oldGenerateSourcesCxfServer.getParentNode().replaceChild(newGenerateSourcesCxfServer,
                oldGenerateSourcesCxfServer);
    } else {

        if (oldExecutions == null) {
            newExecutions = pom.createElement(EXECUTIONS);
            newExecutions.appendChild(newGenerateSourcesCxfServer);

            codegenWsPlugin.appendChild(newExecutions);
        } else {
            newExecutions = oldExecutions;
            newExecutions.appendChild(newGenerateSourcesCxfServer);
            oldExecutions.getParentNode().replaceChild(newExecutions, oldExecutions);
        }
    }

    // Write new XML to disk
    XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom);

}

From source file:com.enonic.vertical.adminweb.MenuHandlerServlet.java

private void moveMenuItemUp(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        ExtendedMap formItems) throws VerticalAdminException {

    String menuXML = (String) session.getAttribute("menuxml");
    Document doc = XMLTool.domparse(menuXML);

    String xpath = "//menuitem[@key = '" + formItems.getString("key") + "']";
    Element elem = (Element) XMLTool.selectNode(doc, xpath);

    Element parent = (Element) elem.getParentNode();
    Element previousSibling = (Element) elem.getPreviousSibling();
    elem = (Element) parent.removeChild(elem);
    doc.importNode(elem, true);// ww w . j  a  v  a2s  . co  m

    if (previousSibling == null)
    // This is the top element, move it to the bottom
    {
        parent.appendChild(elem);
    } else {
        parent.insertBefore(elem, previousSibling);
    }

    session.setAttribute("menuxml", XMLTool.documentToString(doc));

    MultiValueMap queryParams = new MultiValueMap();
    queryParams.put("page", formItems.get("page"));
    queryParams.put("op", "browse");
    queryParams.put("keepxml", "yes");
    queryParams.put("highlight", formItems.get("key"));
    queryParams.put("menukey", formItems.get("menukey"));
    queryParams.put("parentmi", formItems.get("parentmi"));
    queryParams.put("subop", "shiftmenuitems");

    queryParams.put("move_menuitem", formItems.getString("move_menuitem", ""));
    queryParams.put("move_from_parent", formItems.getString("move_from_parent", ""));
    queryParams.put("move_to_parent", formItems.getString("move_to_parent", ""));

    redirectClientToAdminPath("adminpage", queryParams, request, response);
}