Example usage for org.w3c.dom Element getNodeName

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

Introduction

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

Prototype

public String getNodeName();

Source Link

Document

The name of this node, depending on its type; see the table above.

Usage

From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java

/**
 * <p>Load the template BeanDefinition and call {@link #transform(ConfigurableListableBeanFactory, BeanDefinition, Element, ParserContext)}
 * to apply runtime configuration value to it.  <code>builder</code> will be configured to instantiate the bean
 * in the Spring context that we are parsing.</p>
 * //w w w. ja va 2 s  .  com
 * <p>During parsing, an instance of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} is pushed onto <code>ParserContext</code> so
 * that nested tags can access the enclosing template configuration with a call to {@link #findEnclosingTemplateFactory(ParserContext)}.
 * Subclasses can override {@link #newComponentDefinition(String, Object, DefaultListableBeanFactory)} to provide a 
 * subclass of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} to the parser context if necessary.</p>
 */
@Override
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //if we have multiple nested bean definitions, we only parse the template factory
    //once.  this allows configuration changes made by enclosing bean parsers to be inherited
    //by contained beans, which is quite useful.
    DefaultListableBeanFactory templateFactory = findEnclosingTemplateFactory(parserContext);
    TemplateComponentDefinition tcd = null;
    if (templateFactory == null) {

        //no nesting -- load the template XML configuration from the classpath.
        final BeanFactory parentFactory = (BeanFactory) parserContext.getRegistry();
        templateFactory = new DefaultListableBeanFactory(parentFactory);

        //load template bean definitions
        DefaultResourceLoader loader = new DefaultResourceLoader();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(templateFactory);
        reader.setResourceLoader(loader);
        reader.setEntityResolver(new ResourceEntityResolver(loader));
        reader.loadBeanDefinitions(templateResource);

        //propagate factory post-processors from the source factory into the template
        //factory.
        BeanDefinition ppChain = new RootBeanDefinition(ChainingBeanFactoryPostProcessor.class);
        ppChain.getPropertyValues().addPropertyValue("targetFactory", templateFactory);
        parserContext.getReaderContext().registerWithGeneratedName(ppChain);

        //push component definition onto the parser stack for the benefit of
        //nested bean definitions.
        tcd = newComponentDefinition(element.getNodeName(), parserContext.extractSource(element),
                templateFactory);
        parserContext.pushContainingComponent(tcd);
    }

    try {
        //allow subclasses to apply overrides to the template bean definition.
        BeanDefinition def = templateFactory.getBeanDefinition(templateId);
        transform(templateFactory, def, element, parserContext);

        //setup our factory bean to instantiate the modified bean definition upon request.
        builder.addPropertyValue("beanFactory", templateFactory);
        builder.addPropertyValue("beanName", templateId);
        builder.getRawBeanDefinition().setAttribute("id", def.getAttribute("id"));

    } finally {
        if (tcd != null)
            parserContext.popContainingComponent();
    }
}

From source file:com.moviejukebox.reader.MovieJukeboxXMLReader.java

/**
 * Parse a single movie detail XML file/*w  w w  . j  av a  2  s.c o m*/
 *
 * @param xmlFile
 * @param movie
 * @return
 */
public boolean parseMovieXML(File xmlFile, Movie movie) {
    boolean forceDirtyFlag = Boolean.FALSE; // force dirty flag for example when extras have been deleted
    Document xmlDoc;

    try {
        xmlDoc = DOMHelper.getDocFromFile(xmlFile);
    } catch (MalformedURLException error) {
        LOG.error(ERROR_FIXIT, xmlFile.getName());
        LOG.error(SystemTools.getStackTrace(error));
        return Boolean.FALSE;
    } catch (IOException error) {
        LOG.error(ERROR_FIXIT, xmlFile.getName());
        LOG.error(SystemTools.getStackTrace(error));
        return Boolean.FALSE;
    } catch (ParserConfigurationException | SAXException error) {
        LOG.error(ERROR_FIXIT, xmlFile.getName());
        LOG.error(SystemTools.getStackTrace(error));
        return Boolean.FALSE;
    }

    NodeList nlMovies; // Main list of movies, there should only be 1
    Node nMovie; // Node for the movie

    NodeList nlElements; // Reusable NodeList for the other elements
    Node nElements; // Reusable Node for the other elements

    nlMovies = xmlDoc.getElementsByTagName(MOVIE);
    for (int loopMovie = 0; loopMovie < nlMovies.getLength(); loopMovie++) {
        nMovie = nlMovies.item(loopMovie);
        if (nMovie.getNodeType() == Node.ELEMENT_NODE) {
            Element eMovie = (Element) nMovie;

            // Get all the IDs associated with the movie
            nlElements = eMovie.getElementsByTagName("id");
            for (int looper = 0; looper < nlElements.getLength(); looper++) {
                nElements = nlElements.item(looper);
                if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                    Element eId = (Element) nElements;

                    String movieDb = eId.getAttribute(MOVIEDB);
                    if (StringTools.isNotValidString(movieDb)) {
                        movieDb = ImdbPlugin.IMDB_PLUGIN_ID;
                    }
                    movie.setId(movieDb, eId.getTextContent());
                }
            } // End of ID

            // Get the Version the XML was written with
            movie.setMjbVersion(DOMHelper.getValueFromElement(eMovie, "mjbVersion"));

            // Get the Git SHA the XML was written with
            movie.setMjbGitSHA(DOMHelper.getValueFromElement(eMovie, "mjbGitSHA"));

            // Get the date/time the XML was written
            movie.setMjbGenerationDateString(DOMHelper.getValueFromElement(eMovie, "xmlGenerationDate"));

            if (StringTools.isNotValidString(movie.getBaseFilename())) {
                movie.setBaseFilename(DOMHelper.getValueFromElement(eMovie, "baseFilenameBase"));
            }

            if (StringTools.isNotValidString(movie.getBaseName())) {
                movie.setBaseName(DOMHelper.getValueFromElement(eMovie, BASE_FILENAME));
            }

            // Get the title fields
            parseOverridableTitle(movie, eMovie);
            parseOverridableOriginalTitle(movie, eMovie);
            movie.setTitleSort(DOMHelper.getValueFromElement(eMovie, SORT_TITLE));

            // Get the year. We don't care about the attribute as that is the index
            parseOverridableYear(movie, eMovie);

            // Get the release date
            parseOverridableReleaseDate(movie, eMovie);

            // get the show status
            movie.setShowStatus(DOMHelper.getValueFromElement(eMovie, "showStatus"));

            // Get the ratings. We don't care about the RATING as this is a calulated value.
            // So just get the childnodes of the "ratings" node
            nlElements = eMovie.getElementsByTagName("ratings");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eRating = (Element) nElements;

                        String movieDb = eRating.getAttribute(MOVIEDB);
                        if (StringTools.isNotValidString(movieDb)) {
                            movieDb = ImdbPlugin.IMDB_PLUGIN_ID;
                        }
                        movie.addRating(movieDb, Integer.parseInt(eRating.getTextContent()));
                    }
                }
            } // End of Ratings

            // Get the watched flags
            movie.setWatchedNFO(Boolean.parseBoolean(DOMHelper.getValueFromElement(eMovie, "watchedNFO")));
            movie.setWatchedFile(Boolean.parseBoolean(DOMHelper.getValueFromElement(eMovie, "watchedFile")));

            // Get artwork URLS
            movie.setPosterURL(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "posterURL")));
            movie.setFanartURL(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "fanartURL")));
            movie.setBannerURL(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "bannerURL")));
            movie.setClearArtURL(HTMLTools.decodeHtml(DOMHelper.getValueFromElement(eMovie, "clearArtURL")));
            movie.setClearLogoURL(HTMLTools.decodeHtml(DOMHelper.getValueFromElement(eMovie, "clearLogoURL")));
            movie.setTvThumbURL(HTMLTools.decodeHtml(DOMHelper.getValueFromElement(eMovie, "tvThumbURL")));
            movie.setSeasonThumbURL(
                    HTMLTools.decodeHtml(DOMHelper.getValueFromElement(eMovie, "seasonThumbURL")));
            movie.setMovieDiscURL(HTMLTools.decodeHtml(DOMHelper.getValueFromElement(eMovie, "movieDiscURL")));

            // Get artwork files
            movie.setPosterFilename(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "posterFile")));
            movie.setDetailPosterFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "detailPosterFile")));
            movie.setThumbnailFilename(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "thumbnail")));
            movie.setFanartFilename(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "fanartFile")));
            movie.setBannerFilename(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "bannerFile")));
            movie.setWideBannerFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "wideBannerFile")));
            movie.setClearArtFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "clearArtFile")));
            movie.setClearLogoFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "clearLogoFile")));
            movie.setTvThumbFilename(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "tvThumbFile")));
            movie.setSeasonThumbFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "seasonThumbFile")));
            movie.setMovieDiscFilename(
                    HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "movieDiscFile")));

            // Get the plot and outline
            parseOverridablePlot(movie, eMovie);
            parseOverridableOutline(movie, eMovie);

            // Get the quote
            parseOverridableQuote(movie, eMovie);

            // Get the tagline
            parseOverridableTagline(movie, eMovie);

            // Get the company name
            parseOverridableCompany(movie, eMovie);

            // get the runtime
            parseOverridableRuntime(movie, eMovie);

            // get the top 250
            parseOverridableTop250(movie, eMovie);

            // Get the directors
            nlElements = eMovie.getElementsByTagName("directors");
            if (nlElements.getLength() > 0) {
                Element tagElement = (Element) nlElements.item(0);
                nlElements = tagElement.getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element ePerson = (Element) nElements;
                        movie.addDirector(ePerson.getTextContent(), tagElement.getAttribute(SOURCE));
                    }
                }
            }

            // Get the writers
            nlElements = eMovie.getElementsByTagName("writers");
            if (nlElements.getLength() > 0) {
                Element tagElement = (Element) nlElements.item(0);
                nlElements = tagElement.getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element ePerson = (Element) nElements;
                        movie.addWriter(ePerson.getTextContent(), tagElement.getAttribute(SOURCE));
                    }
                }
            }

            // Get the cast
            nlElements = eMovie.getElementsByTagName("cast");
            if (nlElements.getLength() > 0) {
                Element tagElement = (Element) nlElements.item(0);
                nlElements = tagElement.getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element ePerson = (Element) nElements;
                        movie.addActor(ePerson.getTextContent(), tagElement.getAttribute(SOURCE));
                    }
                }
            }

            // Get the country
            parseOverridableCountry(movie, eMovie);

            // Get the genres
            nlElements = eMovie.getElementsByTagName("genres");
            if (nlElements.getLength() > 0) {
                Element tagElement = (Element) nlElements.item(0);
                nlElements = tagElement.getChildNodes();
                List<String> genres = new ArrayList<>();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eGenre = (Element) nElements;
                        genres.add(eGenre.getTextContent());
                    }
                }
                movie.setGenres(genres, tagElement.getAttribute(SOURCE));
            }

            // Process the sets
            nlElements = eMovie.getElementsByTagName("sets");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eSet = (Element) nElements;
                        String order = eSet.getAttribute(ORDER);
                        if (StringTools.isValidString(order)) {
                            movie.addSet(eSet.getTextContent(), Integer.parseInt(order));
                        } else {
                            movie.addSet(eSet.getTextContent());
                        }
                    }
                }
            }

            // Get certification
            parseOverridableCertification(movie, eMovie);

            // Get language
            parseOverridableLanguage(movie, eMovie);

            // Get subtitles
            movie.setSubtitles(DOMHelper.getValueFromElement(eMovie, "subtitles"));

            // Get the TrailerExchange
            movie.setTrailerExchange(
                    DOMHelper.getValueFromElement(eMovie, "trailerExchange").equalsIgnoreCase(YES));

            // Get trailerLastScan date/time
            movie.setTrailerLastScan(DOMHelper.getValueFromElement(eMovie, TRAILER_LAST_SCAN));

            // Get file container
            parseOverridableContainer(movie, eMovie);

            nlElements = eMovie.getElementsByTagName("codecs");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        String codecType = nElements.getNodeName();
                        if (nElements.getChildNodes().getLength() > 0) {
                            for (int cLooper = 0; cLooper < nElements.getChildNodes().getLength(); cLooper++) {
                                Node nCodec = nElements.getChildNodes().item(cLooper);
                                if (nCodec.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eCodec = (Element) nCodec;

                                    Codec codec;
                                    if (CodecType.VIDEO.toString().equalsIgnoreCase(codecType)) {
                                        codec = new Codec(CodecType.VIDEO);
                                    } else {
                                        codec = new Codec(CodecType.AUDIO);
                                    }
                                    codec.setCodecId(eCodec.getAttribute("codecId"));
                                    codec.setCodecIdHint(eCodec.getAttribute("codecIdHint"));
                                    codec.setCodecFormat(eCodec.getAttribute("format"));
                                    codec.setCodecFormatProfile(eCodec.getAttribute("formatProfile"));
                                    codec.setCodecFormatVersion(eCodec.getAttribute("formatVersion"));
                                    codec.setCodecLanguage(eCodec.getAttribute(LANGUAGE));
                                    codec.setCodecBitRate(eCodec.getAttribute("bitrate"));
                                    String tmpValue = eCodec.getAttribute("channels");
                                    if (StringUtils.isNotBlank(tmpValue)) {
                                        codec.setCodecChannels(
                                                Integer.parseInt(eCodec.getAttribute("channels")));
                                    }
                                    codec.setCodec(eCodec.getTextContent().trim());

                                    tmpValue = eCodec.getAttribute(SOURCE);
                                    if (StringTools.isValidString(tmpValue)) {
                                        codec.setCodecSource(CodecSource.fromString(tmpValue));
                                    } else {
                                        codec.setCodecSource(CodecSource.UNKNOWN);
                                    }

                                    movie.addCodec(codec);
                                }
                            } // END of codec information for audio/video
                        }
                    } // END of audio/video codec
                } // END of codecs loop
            } // END of codecs

            // get the resolution
            parseOverridableResolution(movie, eMovie);

            // get the video source
            parseOverridableVideoSource(movie, eMovie);

            // get the video output
            parseOverridableVideoOutput(movie, eMovie);

            // get aspect ratio
            parseOverridableAspectRatio(movie, eMovie);

            // get frames per second
            parseOverridableFramesPerSecond(movie, eMovie);

            // Get navigation info
            movie.setFirst(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "first")));
            movie.setPrevious(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "previous")));
            movie.setNext(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "next")));
            movie.setLast(HTMLTools.decodeUrl(DOMHelper.getValueFromElement(eMovie, "last")));

            // Get the library description, if it's not been set elsewhere (e.g. scanner)
            String tempLibraryDescription = DOMHelper.getValueFromElement(eMovie, "libraryDescription");
            if (StringTools.isNotValidString(movie.getLibraryDescription())) {
                movie.setLibraryDescription(tempLibraryDescription);
            } else if (!movie.getLibraryDescription().equals(tempLibraryDescription)) {
                // The current description is different to the one in the XML
                LOG.debug("Different library description! Setting dirty INFO");
                forceDirtyFlag = Boolean.TRUE;
            }

            // Get prebuf
            movie.setPrebuf(Long.parseLong(DOMHelper.getValueFromElement(eMovie, "prebuf")));

            // Issue 1901: Awards
            nlElements = eMovie.getElementsByTagName("awards");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eAwardEvent = (Element) nElements;
                        AwardEvent awardEvent = new AwardEvent();
                        awardEvent.setName(eAwardEvent.getAttribute(NAME));

                        Node nAward;
                        for (int loopAwards = 0; loopAwards < eAwardEvent.getChildNodes()
                                .getLength(); loopAwards++) {
                            nAward = eAwardEvent.getChildNodes().item(loopAwards);
                            if (nAward.getNodeType() == Node.ELEMENT_NODE) {
                                Element eAward = (Element) nAward;
                                Award award = new Award();

                                award.setName(eAward.getTextContent());
                                award.setNominated(Integer.parseInt(eAward.getAttribute("nominated")));
                                award.setWon(Integer.parseInt(eAward.getAttribute(WON)));
                                award.setYear(Integer.parseInt(eAward.getAttribute(YEAR)));
                                String tmpAward = eAward.getAttribute("wons");
                                if (StringTools.isValidString(tmpAward)) {
                                    award.setWons(Arrays.asList(tmpAward.split(Movie.SPACE_SLASH_SPACE)));
                                }
                                tmpAward = eAward.getAttribute("nominations");
                                if (StringTools.isValidString(tmpAward)) {
                                    award.setNominations(
                                            Arrays.asList(tmpAward.split(Movie.SPACE_SLASH_SPACE)));
                                }

                                awardEvent.addAward(award);
                            }
                        } // End of Awards

                        movie.addAward(awardEvent);
                    }
                }
            } // End of AwardEvents

            // Issue 1897: Cast enhancement
            nlElements = eMovie.getElementsByTagName("people");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();

                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element ePerson = (Element) nElements;
                        Filmography person = new Filmography();

                        person.setCastId(ePerson.getAttribute("cast_id"));
                        person.setCharacter(ePerson.getAttribute(CHARACTER));
                        person.setDepartment(ePerson.getAttribute(DEPARTMENT));
                        person.setDoublage(ePerson.getAttribute("doublage"));
                        person.setId(ePerson.getAttribute("id"));
                        person.setJob(ePerson.getAttribute(JOB));
                        person.setName(ePerson.getAttribute(NAME));
                        person.setOrder(ePerson.getAttribute(ORDER));
                        person.setTitle(ePerson.getAttribute(TITLE));
                        person.setUrl(ePerson.getAttribute(URL));
                        person.setPhotoFilename(ePerson.getAttribute("photoFile"));
                        person.setFilename(ePerson.getTextContent());

                        // Get any "id_???" values
                        for (int loopAttr = 0; loopAttr < ePerson.getAttributes().getLength(); loopAttr++) {
                            Node nPersonAttr = ePerson.getAttributes().item(loopAttr);
                            if (nPersonAttr.getNodeName().startsWith(ID)) {
                                String name = nPersonAttr.getNodeName().replace(ID, "");
                                person.setId(name, nPersonAttr.getNodeValue());
                            }
                        }

                        String source = ePerson.getAttribute(SOURCE);
                        if (StringTools.isValidString(source)) {
                            person.setSource(source);
                            if (person.getDepartment().equalsIgnoreCase(Filmography.DEPT_DIRECTING)) {
                                movie.setOverrideSource(OverrideFlag.PEOPLE_DIRECTORS, source);
                            } else if (person.getDepartment().equalsIgnoreCase(Filmography.DEPT_WRITING)) {
                                movie.setOverrideSource(OverrideFlag.PEOPLE_WRITERS, source);
                            } else if (person.getDepartment().equalsIgnoreCase(Filmography.DEPT_ACTORS)) {
                                movie.setOverrideSource(OverrideFlag.PEOPLE_ACTORS, source);
                            }
                        } else {
                            person.setSource(Movie.UNKNOWN);
                        }
                        movie.addPerson(person);
                    }
                }
            } // End of Cast

            // Issue 2012: Financial information about movie
            nlElements = eMovie.getElementsByTagName("business");
            for (int looper = 0; looper < nlElements.getLength(); looper++) {
                nElements = nlElements.item(looper);
                if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                    Element eBusiness = (Element) nElements;
                    movie.setBudget(eBusiness.getAttribute("budget"));

                    Node nCountry;
                    for (int loopBus = 0; loopBus < eBusiness.getChildNodes().getLength(); loopBus++) {
                        nCountry = eBusiness.getChildNodes().item(loopBus);
                        if (nCountry.getNodeType() == Node.ELEMENT_NODE) {
                            Element eCountry = (Element) nCountry;
                            if ("gross".equalsIgnoreCase(eCountry.getNodeName())) {
                                movie.setGross(eCountry.getAttribute(COUNTRY), eCountry.getTextContent());
                            } else if ("openweek".equalsIgnoreCase(eCountry.getNodeName())) {
                                movie.setOpenWeek(eCountry.getAttribute(COUNTRY), eCountry.getTextContent());
                            }
                        }
                    } // End of budget info
                }
            } // End of business info

            // Issue 2013: Add trivia
            if (ENABLE_TRIVIA) {
                nlElements = eMovie.getElementsByTagName("trivia");
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    movie.addDidYouKnow(nElements.getTextContent());
                }
            } // End of trivia info

            // Get the file list
            nlElements = eMovie.getElementsByTagName("files");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eFile = (Element) nElements;
                        MovieFile movieFile = new MovieFile();

                        try {
                            File mfFile = new File(DOMHelper.getValueFromElement(eFile, "fileLocation"));
                            // Check to see if the file exists, or we are preserving the jukebox
                            if (mfFile.exists() || MovieJukebox.isJukeboxPreserve()) {
                                // Save the file to the MovieFile
                                movieFile.setFile(mfFile);
                            } else {
                                // We can't find this file anymore, so skip it.
                                LOG.debug(
                                        "Missing video file in the XML file ({}), it may have been moved or no longer exist.",
                                        mfFile.getName());
                                continue;
                            }
                        } catch (Exception ignore) {
                            // If there is an error creating the file then don't save anything
                            LOG.debug("Failed parsing file {}", xmlFile.getName());
                            continue;
                        }

                        String attr = eFile.getAttribute(TITLE);
                        if (StringTools.isValidString(attr)) {
                            movieFile.setTitle(attr);
                        }

                        attr = eFile.getAttribute(SEASON);
                        if (StringUtils.isNumeric(attr)) {
                            movieFile.setSeason(Integer.parseInt(attr));
                        }

                        attr = eFile.getAttribute("firstPart");
                        if (StringUtils.isNumeric(attr)) {
                            movieFile.setFirstPart(Integer.parseInt(attr));
                        }

                        attr = eFile.getAttribute("lastPart");
                        if (StringUtils.isNumeric(attr)) {
                            movieFile.setLastPart(Integer.parseInt(attr));
                        }

                        attr = eFile.getAttribute("subtitlesExchange");
                        if (StringTools.isValidString(attr)) {
                            movieFile.setSubtitlesExchange(attr.equalsIgnoreCase(YES));
                        }

                        movieFile.setFilename(DOMHelper.getValueFromElement(eFile, "fileURL"));

                        if (DOMHelper.getValueFromElement(eFile, "fileArchiveName") != null) {
                            movieFile.setArchiveName(DOMHelper.getValueFromElement(eFile, "fileArchiveName"));
                        }

                        // We need to get the part from the fileTitle
                        NodeList nlFileParts = eFile.getElementsByTagName("fileTitle");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    String part = eFileParts.getAttribute(PART);
                                    String source = eFileParts.getAttribute(SOURCE);
                                    if (StringUtils.isNumeric(part)) {
                                        movieFile.setTitle(NumberUtils.toInt(part, 0),
                                                eFileParts.getTextContent(), source);
                                    } else {
                                        movieFile.setTitle(eFileParts.getTextContent(), source);
                                    }
                                }
                            }
                        }

                        // Get the airs info
                        nlFileParts = eFile.getElementsByTagName("airsInfo");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);

                                    movieFile.setAirsAfterSeason(part, eFileParts.getAttribute("afterSeason"));
                                    movieFile.setAirsBeforeEpisode(part,
                                            eFileParts.getAttribute("beforeEpisode"));
                                    movieFile.setAirsBeforeSeason(part,
                                            eFileParts.getAttribute("beforeSeason"));
                                }
                            }
                        }

                        // Get first aired information
                        nlFileParts = eFile.getElementsByTagName("firstAired");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    String source = eFileParts.getAttribute(SOURCE);
                                    movieFile.setFirstAired(part, eFileParts.getTextContent(), source);
                                }
                            }
                        }

                        // get the file plot
                        nlFileParts = eFile.getElementsByTagName("filePlot");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    String source = eFileParts.getAttribute(SOURCE);
                                    movieFile.setPlot(part, eFileParts.getTextContent(), source, Boolean.TRUE);
                                }
                            }
                        }

                        // get the file rating
                        nlFileParts = eFile.getElementsByTagName("fileRating");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    String source = eFileParts.getAttribute(SOURCE);
                                    movieFile.setRating(part, eFileParts.getTextContent(), source);
                                }
                            }
                        }

                        // get the file image url
                        nlFileParts = eFile.getElementsByTagName("fileImageURL");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    movieFile.setVideoImageURL(part,
                                            HTMLTools.decodeUrl(eFileParts.getTextContent()));
                                }
                            }
                        }

                        // get the file image filename
                        nlFileParts = eFile.getElementsByTagName("fileImageFile");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    movieFile.setVideoImageFilename(part,
                                            HTMLTools.decodeUrl(eFileParts.getTextContent()));
                                }
                            }
                        }

                        // get the file IDs
                        nlFileParts = eFile.getElementsByTagName("fileId");
                        if (nlFileParts.getLength() > 0) {
                            for (int looperFile = 0; looperFile < nlFileParts.getLength(); looperFile++) {
                                Node nFileParts = nlFileParts.item(looperFile);
                                if (nFileParts.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eFileParts = (Element) nFileParts;
                                    int part = NumberUtils.toInt(eFileParts.getAttribute(PART), 1);
                                    String source = eFileParts.getAttribute(SOURCE);
                                    movieFile.setId(part, source, eFileParts.getTextContent());
                                }
                            }
                        }

                        NodeList nlAttachments = eMovie.getElementsByTagName("attachments");
                        if (nlAttachments.getLength() > 0) {
                            nlAttachments = nlAttachments.item(0).getChildNodes();
                            for (int looperAtt = 0; looperAtt < nlAttachments.getLength(); looperAtt++) {
                                Node nAttachment = nlAttachments.item(looperAtt);
                                if (nAttachment.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eAttachment = (Element) nAttachment;
                                    Attachment attachment = new Attachment();
                                    attachment.setType(
                                            AttachmentType.fromString(eAttachment.getAttribute("type")));
                                    attachment.setAttachmentId(Integer.parseInt(
                                            DOMHelper.getValueFromElement(eAttachment, "attachmentId")));
                                    attachment.setContentType(ContentType.fromString(
                                            DOMHelper.getValueFromElement(eAttachment, "contentType")));
                                    attachment.setMimeType(
                                            DOMHelper.getValueFromElement(eAttachment, "mimeType"));
                                    attachment.setPart(Integer
                                            .parseInt(DOMHelper.getValueFromElement(eAttachment, "part")));
                                    attachment.setSourceFile(movieFile.getFile());
                                    movieFile.addAttachment(attachment);
                                }
                            }
                        }

                        // Parse watched 
                        String watchedDateString = DOMHelper.getValueFromElement(eFile, "watchedDate");
                        final long watchedDate;
                        if (StringTools.isNotValidString(watchedDateString)) {
                            watchedDate = 0;
                        } else {
                            // strip milliseconds
                            Calendar cal = Calendar.getInstance();
                            cal.setTimeInMillis(DateTime.parse(watchedDateString).toMillis());
                            cal.set(Calendar.MILLISECOND, 0);
                            watchedDate = cal.getTimeInMillis();
                        }
                        final boolean watched = Boolean.parseBoolean(eFile.getAttribute("watched"));
                        movieFile.setWatched(watched, watchedDate);

                        // This is not a new file
                        movieFile.setNewFile(Boolean.FALSE);

                        // Add the movie file to the movie
                        movie.addMovieFile(movieFile);
                    }
                }
            } // END of files

            // Get the extra list
            nlElements = eMovie.getElementsByTagName("extras");
            if (nlElements.getLength() > 0) {
                nlElements = nlElements.item(0).getChildNodes();
                for (int looper = 0; looper < nlElements.getLength(); looper++) {
                    nElements = nlElements.item(looper);
                    if (nElements.getNodeType() == Node.ELEMENT_NODE) {
                        Element eExtra = (Element) nElements;

                        String extraTitle = eExtra.getAttribute(TITLE);
                        String extraFilename = eExtra.getTextContent();

                        if (!extraTitle.isEmpty() && !extraFilename.isEmpty()) {
                            boolean exist = Boolean.FALSE;
                            if (extraFilename.startsWith("http:")) {
                                // This is a URL from a NFO file
                                ExtraFile ef = new ExtraFile();
                                ef.setNewFile(Boolean.FALSE);
                                ef.setTitle(extraTitle);
                                ef.setFilename(extraFilename);
                                movie.addExtraFile(ef, Boolean.FALSE); // Add to the movie, but it's not dirty
                                exist = Boolean.TRUE;
                            } else {
                                // Check for existing files
                                for (ExtraFile ef : movie.getExtraFiles()) {
                                    // Check if the movie has already the extra file
                                    if (ef.getFilename().equals(extraFilename)) {
                                        exist = Boolean.TRUE;
                                        // the extra file is old
                                        ef.setNewFile(Boolean.FALSE);
                                        break;
                                    }
                                }
                            }

                            if (!exist) {
                                // the extra file has been deleted so force the dirty flag
                                forceDirtyFlag = Boolean.TRUE;
                            }
                        }
                    }
                }
            } // END of extras

        } // End of ELEMENT_NODE
    } // End of Movie Loop

    // This is a new movie, so clear the current dirty flags
    movie.clearDirty();
    movie.setDirty(DirtyFlag.INFO, forceDirtyFlag || movie.hasNewMovieFiles() || movie.hasNewExtraFiles());

    return Boolean.TRUE;
}

From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

private synchronized DuplicateChildElementObject isChildElement(final Element origianlRootElement,
        final Element patchElement) {

    DuplicateChildElementObject childElementObject = new DuplicateChildElementObject();

    NodeList originalItems = origianlRootElement.getChildNodes();
    int item_number = originalItems.getLength();

    childElementObject.setNeedDuplicate(true);
    childElementObject.setElement(origianlRootElement);
    /*//from ww w .  j a v a2  s .c om
    for (int i = 0; i < item_number; i++) {
       Element originalItem = null;
       //logger.debug("node name: " + DomUtils
       //.elementToString(originalItems.item(i)) + " node type: " + originalItems.item(i).getNodeType());
       if (originalItems.item(i).getNodeType() == Node.ELEMENT_NODE){
    originalItem = (Element) originalItems.item(i);
       }
            
       if (!originalItem.getNodeName().equals(patchElement.getNodeName())) {
    continue;
       }
               
       if (originalItem.isEqualNode(patchElement)) {
    childElementObject.setNeedDuplicate(false);
    childElementObject.setElement(originalItem);
    return childElementObject;
       }
    }
    */

    for (int i = 0; i < item_number; i++) {
        Element originalItem = null;
        if (originalItems.item(i).getNodeType() == Node.ELEMENT_NODE) {
            originalItem = (Element) originalItems.item(i);
        }

        if (!originalItem.getNodeName().equals(patchElement.getNodeName())) {
            continue;
        }

        if (isEqualNode(originalItem, patchElement)) {
            if (hasEqualAttributes(originalItem, patchElement)) {
                childElementObject.setNeedDuplicate(false);
                childElementObject.setElement(originalItem);
                return childElementObject;
            } else {
                childElementObject.setNeedDuplicate(true);
                childElementObject.setElement(origianlRootElement);
                return childElementObject;
            }
        }
    }

    return childElementObject;
}

From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

@Override
public synchronized Map<String, Object> addElementByPath(final String path, final String originalXml,
        final String elementXml, boolean generateId) throws SAXException, IOException {
    Assert.hasText(path);/*from   w  w w  .j a va2 s. c om*/
    Assert.hasText(originalXml);
    Assert.hasText(elementXml);

    logger.debug(elementXml);

    Document originalDom = parse(originalXml);

    Document elementDom = parse(elementXml);

    Document finalDom = originalDom;

    Element finalDomRoot = (Element) finalDom.getFirstChild();

    Element elementRoot = (Element) elementDom.getFirstChild();

    List<String> nodeList = getNodeList(path);
    logger.trace("nodeList: " + nodeList + " =? ");

    Assert.isTrue(nodeList.size() > 0);

    // remove first one, should be protocol
    nodeList.remove(0);

    String newElementName = nodeList.get(nodeList.size() - 1);

    logger.trace("adding <" + newElementName + ">");
    // remove last one, should be <drug>, we are attaching the drug into
    // drugs... so we want the rightmost element to be drugs...
    nodeList.remove(nodeList.size() - 1);

    Element currentNode = finalDomRoot;
    int c = 0;
    for (String n : nodeList) {
        NodeList cur = currentNode.getElementsByTagName(n);
        String curName = currentNode.getNodeName();
        c = cur.getLength();

        if (c > 1) {
            throw new RuntimeException("illeagl xml structure; find " + c + " elements with name " + n);
        }

        if (c == 0) {
            logger.debug("empty node...; " + n + " doesn't exist under " + curName);

            Element newN = finalDom.createElement(n);
            currentNode.appendChild(newN);

            currentNode = newN;
            continue;
        }

        currentNode = (Element) cur.item(0);

    }

    logger.trace("rightmost element: " + currentNode.getNodeName());

    String id = "";

    if (generateId) {
        // using jdk UUID as uuid generator...
        id = UUID.randomUUID().toString();

        Assert.isTrue(newElementName.equals(elementRoot.getNodeName()),
                "the element you are adding does not match the rightmost element name in the path!");

        elementRoot.setAttribute("id", id);
    }
    currentNode.appendChild(finalDom.importNode(elementRoot, true));

    Map<String, Object> resultMap = new HashMap<String, Object>(3);
    resultMap.put("finalXml", DomUtils.elementToString(finalDom));
    resultMap.put("elementXml", DomUtils.elementToString(elementDom));
    resultMap.put("elementId", id);
    return resultMap;
}

From source file:lucee.runtime.img.Image.java

private void addMetaddata(Struct parent, String name, Node node) {

    // attributes
    NamedNodeMap attrs = node.getAttributes();
    Attr attr;/* w  w w .j  a  va 2  s  .  c  o  m*/
    int len = attrs.getLength();
    if (len == 1 && "value".equals(attrs.item(0).getNodeName())) {
        parent.setEL(name, attrs.item(0).getNodeValue());
    } else {
        Struct sct = metaGetChild(parent, name);
        for (int i = attrs.getLength() - 1; i >= 0; i--) {
            attr = (Attr) attrs.item(i);
            sct.setEL(attr.getName(), attr.getValue());
        }
    }

    // child nodes
    NodeList children = XMLUtil.getChildNodes(node, Node.ELEMENT_NODE);
    Element el;
    for (int i = children.getLength() - 1; i >= 0; i--) {
        el = (Element) children.item(i);
        Struct sct = metaGetChild(parent, name);
        addMetaddata(sct, el.getNodeName(), children.item(i));
    }
}

From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

/**
 * Thread-safety tested/* www  . j  av  a2 s.com*/
 */
@Override
public Map<String, Object> updateElementByPathById(String path, final String originalXml, String elementId,
        final String elementXml) throws SAXException, IOException {

    Assert.hasText(path);
    Assert.hasText(elementId);
    Assert.hasText(originalXml);
    Assert.hasText(elementId);

    Document originalDom = parse(originalXml);

    Document elementDom = parse(elementXml);

    Document finalDom = originalDom;

    Element finalDomRoot = (Element) finalDom.getFirstChild();

    Element elementRoot = (Element) elementDom.getFirstChild();

    List<String> nodeList = getNodeList(path);
    logger.trace("nodeList: " + nodeList + " =? ");

    // the root node of the path should be the same as the root node of
    // the originalXml
    Assert.isTrue(nodeList.size() > 0 && nodeList.get(0).equals(finalDomRoot.getNodeName()));

    // remove first one, should be protocol
    nodeList.remove(0);

    String elementToDeleteName = nodeList.get(nodeList.size() - 1);

    logger.trace("adding <" + elementToDeleteName + ">");
    // remove last one, should be <drug>, we are attaching the drug into
    // drugs... so we want the rightmost element to be drugs...
    nodeList.remove(nodeList.size() - 1);

    Element currentNode = finalDomRoot;
    int c = 0;
    for (String n : nodeList) {
        NodeList cur = currentNode.getElementsByTagName(n);

        c = cur.getLength();

        if (c > 1) {
            throw new RuntimeException("illeagl xml structure; find " + c + " elements with name " + n);
        }

        if (c == 0) {
            throw new RuntimeException("illeagl xml structure; " + n + " doesn't exist");
        }

        currentNode = (Element) cur.item(0);

    }

    logger.trace("rightmost element: " + currentNode.getNodeName());

    elementRoot.setAttribute("id", elementId);

    Node newChild = finalDom.importNode(elementRoot, true);
    NodeList nodes = currentNode.getChildNodes();

    int l = nodes.getLength();

    logger.trace("lenght: " + l);

    for (int i = 0; i < l; i++) {
        Element cc = (Element) nodes.item(i);

        if (cc.getAttribute("id").equals(elementId)) {
            currentNode.replaceChild(newChild, cc);
            break;
        }
    }

    Map<String, Object> resultMap = new HashMap<String, Object>(3);
    resultMap.put("finalXml", DomUtils.elementToString(finalDom));
    resultMap.put("elementXml", DomUtils.elementToString(elementDom));
    resultMap.put("elementId", elementId);
    return resultMap;
}

From source file:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

/**
 * If the xpath identifies multiple elements, it will only add to the first
 * element, if there is no such parent element, it will just add it...
 *///from ww w.  j a v  a 2s.c o  m
@Override
public synchronized Map<String, Object> addSubElementToElementIdentifiedByXPath(final String parentElementXPath,
        final String originalXml, final String elementXml, boolean generateId)
        throws SAXException, IOException, XPathExpressionException {
    Assert.hasText(parentElementXPath);
    Assert.hasText(originalXml);
    Assert.hasText(elementXml);

    Document originalDom = parse(originalXml);

    Document finalDom = originalDom;

    Document elementDom = parse(elementXml);

    Element elementRoot = (Element) elementDom.getFirstChild();

    XPath xPath = getXPathInstance();

    // find all the nodes specified by xPathString in the finalDom, and
    // delete them all
    NodeList existingNodeList = (NodeList) (xPath.evaluate(parentElementXPath, finalDom,
            XPathConstants.NODESET));

    int el = existingNodeList.getLength();

    String id = "";

    Element currentNode = finalDom.getDocumentElement();
    if (el == 0) { // doesn't exist, create the parent...
        List<String> nodeList = getNodeList(parentElementXPath);

        // remove first one, should be protocol
        nodeList.remove(0);

        int c = 0;
        for (String n : nodeList) {
            NodeList cur = currentNode.getElementsByTagName(n);
            String curName = currentNode.getNodeName();
            c = cur.getLength();

            if (c > 1) {
                throw new RuntimeException("illeagl xml structure; find " + c + " elements with name " + n);
            }

            if (c == 0) {
                logger.debug("empty node...; " + n + " doesn't exist under " + curName);

                Element newN = finalDom.createElement(n);
                currentNode.appendChild(newN);

                currentNode = newN;
                continue;
            }

            currentNode = (Element) cur.item(0);

        }
    } else if (el > 0) {
        currentNode = (Element) existingNodeList.item(0); // only the first
        // one
    }

    if (generateId) {
        // using jdk UUID as uuid generator...
        id = UUID.randomUUID().toString();

        elementRoot.setAttribute("id", id);
    }

    currentNode.appendChild(finalDom.importNode(elementRoot, true));
    /*
     * for(int i = 0; i < el; i++){ Node c = existingNodeList.item(i);
     * 
     * if (generateId) { // using jdk UUID as uuid generator... String id =
     * UUID.randomUUID().toString();
     * 
     * elementRoot.setAttribute("id", id); }
     * 
     * c.appendChild(finalDom.importNode(elementRoot, true));
     * 
     * }
     */
    logger.trace(DomUtils.elementToString(finalDom));

    Map<String, Object> resultMap = new HashMap<String, Object>(3);
    resultMap.put("finalXml", DomUtils.elementToString(finalDom));
    resultMap.put("elementXml", DomUtils.elementToString(elementDom));
    resultMap.put("elementId", id);
    return resultMap;

}

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

private void populateOriginalMetadata(Element root, Deque<String> nameStack) {
    String name = root.getNodeName();
    if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment")
            && !name.equals("LMSDataContainerHeader")) {
        nameStack.push(name);//from   w ww  . j  a v a 2 s  .co m

        String suffix = root.getAttribute("Identifier");
        String value = root.getAttribute("Variant");
        if (suffix == null || suffix.trim().length() == 0) {
            suffix = root.getAttribute("Description");
        }
        StringBuffer key = new StringBuffer();
        final Iterator<String> nameStackIterator = nameStack.descendingIterator();
        while (nameStackIterator.hasNext()) {
            final String k = nameStackIterator.next();
            key.append(k);
            key.append("|");
        }
        if (suffix != null && value != null && suffix.length() > 0 && value.length() > 0
                && !suffix.equals("HighInteger") && !suffix.equals("LowInteger")) {
            addSeriesMetaList(key.toString() + suffix, value);
        } else {
            NamedNodeMap attributes = root.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                Attr attr = (Attr) attributes.item(i);
                if (!attr.getName().equals("HighInteger") && !attr.getName().equals("LowInteger")) {
                    addSeriesMeta(key.toString() + attr.getName(), attr.getValue());
                }
            }
        }
    }

    NodeList children = root.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Object child = children.item(i);
        if (child instanceof Element) {
            populateOriginalMetadata((Element) child, nameStack);
        }
    }

    if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment")
            && !name.equals("LMSDataContainerHeader")) {
        nameStack.pop();
    }
}

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;
        }//  w  w w .  j  ava 2 s  . co  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:edu.uams.clara.webapp.xml.processor.impl.DefaultXmlProcessorImpl.java

private synchronized String duplicate(final Document originalDom, final Element originalRootElement,
        final Element patchElement) throws Exception {

    boolean isdone = false;
    Element parentElement = null;

    DuplicateChildElementObject childElementObject = isChildElement(originalRootElement, patchElement);
    if (!childElementObject.isNeedDuplicate()) {
        isdone = true;/* w  w w .jav  a 2  s  .com*/
        parentElement = childElementObject.getElement();
    } else if (childElementObject.getElement() != null) {
        parentElement = childElementObject.getElement();
    } else {
        parentElement = originalRootElement;
    }

    String son_name = patchElement.getNodeName();

    Element subITEM = null;
    if (!isdone) {
        subITEM = originalDom.createElement(son_name);

        if (patchElement.hasChildNodes()) {
            if (patchElement.getFirstChild().getNodeType() == Node.TEXT_NODE) {
                subITEM.setTextContent(patchElement.getTextContent());

            }
        }

        if (patchElement.hasAttributes()) {
            NamedNodeMap attributes = patchElement.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                String attribute_name = attributes.item(i).getNodeName();
                String attribute_value = attributes.item(i).getNodeValue();
                subITEM.setAttribute(attribute_name, attribute_value);
            }
        }
        parentElement.appendChild(subITEM);
    } else {
        subITEM = parentElement;
    }

    NodeList sub_messageItems = patchElement.getChildNodes();
    int sub_item_number = sub_messageItems.getLength();
    logger.debug("patchEl: " + DomUtils.elementToString(patchElement) + "length: " + sub_item_number);
    if (sub_item_number == 0) {
        isdone = true;
    } else {
        for (int j = 0; j < sub_item_number; j++) {
            if (sub_messageItems.item(j).getNodeType() == Node.ELEMENT_NODE) {
                Element sub_messageItem = (Element) sub_messageItems.item(j);
                logger.debug("node name: " + DomUtils.elementToString(subITEM) + " node type: "
                        + subITEM.getNodeType());
                duplicate(originalDom, subITEM, sub_messageItem);
            }

        }
    }

    return (parentElement != null) ? DomUtils.elementToString(parentElement) : "";
}