Example usage for org.w3c.dom Element getTagName

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

Introduction

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

Prototype

public String getTagName();

Source Link

Document

The name of the element.

Usage

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

private static boolean addOrUpdateElements(Element original, Element proposed,
        boolean originalDocumentChanged) {
    NodeList proposedChildren = proposed.getChildNodes();
    for (int i = 0; i < proposedChildren.getLength(); i++) { // check
                                                             // proposed
                                                             // elements and
                                                             // compare to
                                                             // originals to
                                                             // find out if
                                                             // we need to
                                                             // add or
                                                             // replace
                                                             // elements
        Node node = proposedChildren.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element proposedElement = (Element) node;
            String proposedId = proposedElement.getAttribute("id");
            if (proposedId.length() != 0) { // only proposed elements with
                                            // an id will be considered
                Element originalElement = XmlUtils.findFirstElement("//*[@id='" + proposedId + "']", original);
                if (null == originalElement) { // insert proposed element
                                               // given the original
                                               // document has no element
                                               // with a matching id
                    Element placeHolder = XmlUtils.findFirstElementByName("util:placeholder", original);
                    if (placeHolder != null) { // insert right before place
                                               // holder if we can find it
                        placeHolder.getParentNode().insertBefore(
                                original.getOwnerDocument().importNode(proposedElement, false), placeHolder);
                    } else { // find the best place to insert the element
                        if (proposed.getAttribute("id").length() != 0
                                || proposed.getTagName().substring(2).matches(":[a-z].*")
                                || proposed.getTagName().equals("fx:Declarations")) { // try to find
                                                                                                                                                                                              // the id of
                                                                                                                                                                                              // the
                                                                                                                                                                                              // proposed
                                                                                                                                                                                              // element's
                                                                                                                                                                                              // parent id
                                                                                                                                                                                              // in
                                                                                                                                                                                              // the
                                                                                                                                                                                              // original
                                                                                                                                                                                              // document
                            Element originalParent = XmlUtils.findFirstElement(
                                    "//*[@id='" + proposed.getAttribute("id") + "']", original);
                            if (originalParent != null) { // found parent
                                                          // with the same
                                                          // id, so we can
                                                          // just add it as
                                                          // new child
                                originalParent.appendChild(
                                        original.getOwnerDocument().importNode(proposedElement, false));
                            } else if (proposed.getTagName().equals("fx:Declarations")) {
                                originalParent = XmlUtils.findFirstElementByName("fx:Declarations", original);
                                originalParent.appendChild(
                                        original.getOwnerDocument().importNode(proposedElement, true));
                            } else if (proposed.getTagName().substring(2).matches(":[a-z].*")) {
                                // Likely an attribute tag rather than a
                                // component, thus not allowed to have an
                                // id,
                                // so we must match on the next level up
                                Element proposedParent = proposed.getParentNode()
                                        .getNodeType() == Node.ELEMENT_NODE ? (Element) proposed.getParentNode()
                                                : null;
                                if (proposedParent != null && proposedParent.getAttribute("id").length() != 0) {
                                    String attrTag = proposed.getTagName()
                                            .substring(proposed.getTagName().indexOf(":") + 1);
                                    originalParent = XmlUtils.findFirstElement(
                                            "//*[@id='" + proposedParent.getAttribute("id") + "']/" + attrTag,
                                            original);
                                    if (originalParent != null) { // found a
                                                                  // matching
                                                                  // parent,
                                                                  // so we
                                                                  // can
                                                                  // just
                                                                  // add it
                                                                  // as new
                                                                  // child
                                        originalParent.appendChild(
                                                original.getOwnerDocument().importNode(proposedElement, false));
                                    }/*from   www.  j  a v  a 2  s . c  om*/
                                }
                            }
                        }
                    }
                    originalDocumentChanged = true;
                } else { // we found an element in the original document with
                         // a matching id
                    String originalElementHashCode = originalElement.getAttribute("z");
                    if (originalElementHashCode.length() > 0) { // only act
                                                                // if a hash
                                                                // code
                                                                // exists
                        if ("?".equals(originalElementHashCode) || originalElementHashCode
                                .equals(MxmlRoundTripUtils.calculateUniqueKeyFor(originalElement))) { // only
                                                                                                                                                                        // act
                                                                                                                                                                        // if
                                                                                                                                                                        // hash
                                                                                                                                                                        // codes
                                                                                                                                                                        // match
                                                                                                                                                                        // (no
                                                                                                                                                                        // user
                                                                                                                                                                        // changes
                                                                                                                                                                        // in
                                                                                                                                                                        // the
                                                                                                                                                                        // element)
                                                                                                                                                                        // or
                                                                                                                                                                        // the
                                                                                                                                                                        // user
                                                                                                                                                                        // requests
                                                                                                                                                                        // for
                                                                                                                                                                        // the
                                                                                                                                                                        // hash
                                                                                                                                                                        // code
                                                                                                                                                                        // to
                                                                                                                                                                        // be
                                                                                                                                                                        // regenerated
                            if (!equalElements(originalElement, proposedElement)) { // check if the
                                                                                    // elements have
                                                                                    // equal contents
                                originalElement.getParentNode().replaceChild(
                                        original.getOwnerDocument().importNode(proposedElement, false),
                                        originalElement); // replace
                                                                                                                                                                       // the
                                                                                                                                                                       // original
                                                                                                                                                                       // with
                                                                                                                                                                       // the
                                                                                                                                                                       // proposed
                                                                                                                                                                       // element
                                originalDocumentChanged = true;
                            }
                            if ("?".equals(originalElementHashCode)) { // replace
                                                                       // z
                                                                       // if
                                                                       // the
                                                                       // user
                                                                       // sets
                                                                       // its
                                                                       // value
                                                                       // to
                                                                       // '?'
                                                                       // as
                                                                       // an
                                                                       // indication
                                                                       // that
                                                                       // roo
                                                                       // should
                                                                       // take
                                                                       // over
                                                                       // the
                                                                       // management
                                                                       // of
                                                                       // this
                                                                       // element
                                                                       // again
                                originalElement.setAttribute("z",
                                        MxmlRoundTripUtils.calculateUniqueKeyFor(proposedElement));
                                originalDocumentChanged = true;
                            }
                        } else { // if hash codes don't match we will mark the
                                 // element as z="user-managed"
                            if (!originalElementHashCode.equals("user-managed")) {
                                originalElement.setAttribute("z", "user-managed"); // mark the element
                                                                                   // as
                                                                                   // 'user-managed'
                                                                                   // if the hash
                                                                                   // codes don't
                                                                                   // match any more
                                originalDocumentChanged = true;
                            }
                        }
                    }
                }
            }
            originalDocumentChanged = addOrUpdateElements(original, proposedElement, originalDocumentChanged); // walk
                                                                                                               // through
                                                                                                               // the
                                                                                                               // document
                                                                                                               // tree
                                                                                                               // recursively
        }
    }
    return originalDocumentChanged;
}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

private static boolean equalElements(Element a, Element b) {
    if (!a.getTagName().equals(b.getTagName())) {
        return false;
    }/*from   w w  w .ja  v a2 s  . c o m*/
    if (a.getAttributes().getLength() != b.getAttributes().getLength()) {
        return false;
    }
    NamedNodeMap attributes = a.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node node = attributes.item(i);
        if (!node.getNodeName().equals("z") && !node.getNodeName().startsWith("_")) {
            if (b.getAttribute(node.getNodeName()).length() == 0
                    || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue())) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternJspMetadataListener.java

/** {@link org.springframework.roo.addon.web.mvc.jsp.JspViewManager#addCommonAttributes(FieldMetadata, Element)} */
private void addCommonAttributes(FieldMetadata field, Element fieldElement) {
    AnnotationMetadata annotationMetadata;
    if (field.getFieldType().equals(new JavaType(Integer.class.getName()))
            || field.getFieldType().getFullyQualifiedTypeName().equals(int.class.getName())
            || field.getFieldType().equals(new JavaType(Short.class.getName()))
            || field.getFieldType().getFullyQualifiedTypeName().equals(short.class.getName())
            || field.getFieldType().equals(new JavaType(Long.class.getName()))
            || field.getFieldType().getFullyQualifiedTypeName().equals(long.class.getName())
            || field.getFieldType().equals(new JavaType("java.math.BigInteger"))) {
        fieldElement.setAttribute("validationMessageCode", "field_invalid_integer");
    } else if (uncapitalize(field.getFieldName().getSymbolName()).contains("email")) {
        fieldElement.setAttribute("validationMessageCode", "field_invalid_email");
    } else if (field.getFieldType().equals(new JavaType(Double.class.getName()))
            || field.getFieldType().getFullyQualifiedTypeName().equals(double.class.getName())
            || field.getFieldType().equals(new JavaType(Float.class.getName()))
            || field.getFieldType().getFullyQualifiedTypeName().equals(float.class.getName())
            || field.getFieldType().equals(new JavaType("java.math.BigDecimal"))) {
        fieldElement.setAttribute("validationMessageCode", "field_invalid_number");
    }/*from w ww.j a va  2  s  .c o  m*/
    if (FIELD_INPUT_ELEMENT.equals(fieldElement.getTagName())
            && null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    new JavaType("javax.validation.constraints.Min")))) {
        AnnotationAttributeValue<?> min = annotationMetadata.getAttribute(new JavaSymbolName("value"));
        if (min != null) {
            fieldElement.setAttribute("min", min.getValue().toString());
        }
    }
    if (FIELD_INPUT_ELEMENT.equals(fieldElement.getTagName())
            && null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    new JavaType("javax.validation.constraints.Max")))
            && !FIELD_TEXTAREA_ELEMENT.equals(fieldElement.getTagName())) {
        AnnotationAttributeValue<?> maxA = annotationMetadata.getAttribute(new JavaSymbolName("value"));
        if (maxA != null) {
            fieldElement.setAttribute(MAX_ATTRIBUTE, maxA.getValue().toString());
        }
    }
    if (FIELD_INPUT_ELEMENT.equals(fieldElement.getTagName())
            && null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    new JavaType("javax.validation.constraints.DecimalMin")))
            && !FIELD_TEXTAREA_ELEMENT.equals(fieldElement.getTagName())) {
        AnnotationAttributeValue<?> decimalMin = annotationMetadata.getAttribute(new JavaSymbolName("value"));
        if (decimalMin != null) {
            fieldElement.setAttribute("decimalMin", decimalMin.getValue().toString());
        }
    }
    if (FIELD_INPUT_ELEMENT.equals(fieldElement.getTagName())
            && null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    new JavaType("javax.validation.constraints.DecimalMax")))) {
        AnnotationAttributeValue<?> decimalMax = annotationMetadata.getAttribute(new JavaSymbolName("value"));
        if (decimalMax != null) {
            fieldElement.setAttribute("decimalMax", decimalMax.getValue().toString());
        }
    }
    if (null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
            new JavaType("javax.validation.constraints.Pattern")))) {
        AnnotationAttributeValue<?> regexp = annotationMetadata.getAttribute(new JavaSymbolName("regexp"));
        if (regexp != null) {
            fieldElement.setAttribute("validationRegex", regexp.getValue().toString());
        }
    }
    if (FIELD_INPUT_ELEMENT.equals(fieldElement.getTagName())
            && null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    new JavaType("javax.validation.constraints.Size")))) {
        AnnotationAttributeValue<?> max = annotationMetadata.getAttribute(new JavaSymbolName(MAX_ATTRIBUTE));
        if (max != null) {
            fieldElement.setAttribute(MAX_ATTRIBUTE, max.getValue().toString());
        }
        AnnotationAttributeValue<?> min = annotationMetadata.getAttribute(new JavaSymbolName("min"));
        if (min != null) {
            fieldElement.setAttribute("min", min.getValue().toString());
        }
    }
    if (null != (annotationMetadata = MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
            new JavaType("javax.validation.constraints.NotNull")))) {
        String tagName = fieldElement.getTagName();
        if (tagName.endsWith("textarea") || tagName.endsWith("input") || tagName.endsWith("datetime")
                || tagName.endsWith("textarea") || tagName.endsWith("select")
                || tagName.endsWith("reference")) {
            fieldElement.setAttribute("required", TRUE_VALUE);
        }
    }
    if (field.getCustomData().keySet().contains(CustomDataKeys.COLUMN_FIELD)) {
        @SuppressWarnings("unchecked")
        Map<String, Object> values = (Map<String, Object>) field.getCustomData()
                .get(CustomDataKeys.COLUMN_FIELD);
        if (values.keySet().contains("nullable") && ((Boolean) values.get("nullable")) == false) {
            fieldElement.setAttribute("required", TRUE_VALUE);
        }
    }
    // Disable form binding for nested fields (mainly PKs)
    if (field.getFieldName().getSymbolName().contains(".")) {
        fieldElement.setAttribute("disableFormBinding", TRUE_VALUE);
    }
}

From source file:org.infoscoop.service.GadgetResourceService.java

private byte[] validateGadgetData(String type, String path, String name, byte[] data) {
    Document gadgetDoc;/*from   www .  j av a 2 s  . co  m*/

    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setValidating(false);
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        builder.setEntityResolver(NoOpEntityResolver.getInstance());
        gadgetDoc = builder.parse(new ByteArrayInputStream(data));

        Element moduleNode = gadgetDoc.getDocumentElement();
        NodeList contentNodes = moduleNode.getElementsByTagName("Content");
        //The preparations for Locale tag
        NodeList modulePrefsList = gadgetDoc.getElementsByTagName("ModulePrefs");

        if (!"Module".equals(moduleNode.getTagName()) || contentNodes == null || contentNodes.getLength() == 0
                || modulePrefsList == null || modulePrefsList.getLength() == 0) {
            throw new GadgetResourceException("It is an invalid gadget module. ",
                    "ams_gadgetResourceInvalidGadgetModule");
        }

        Element iconElm = (Element) XPathAPI.selectSingleNode(gadgetDoc, "/Module/ModulePrefs/Icon");
        if (iconElm != null) {
            String iconUrl = iconElm.getTextContent();
            for (int i = 0; i < modulePrefsList.getLength(); i++) {
                Element modulePrefs = (Element) modulePrefsList.item(i);
                if (modulePrefs.hasAttribute("resource_url")) {
                    iconUrl = modulePrefs.getAttribute("resource_url") + iconUrl;
                    break;
                }
            }
            gadgetIconDAO.insertUpdate(type, iconUrl);
        } else {
            gadgetIconDAO.insertUpdate(type, "");
        }

        return XmlUtil.dom2String(gadgetDoc).getBytes("UTF-8");
    } catch (GadgetResourceException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new GadgetResourceException("It is an invalid gadget module. ",
                "ams_gadgetResourceInvalidGadgetModule", ex);
    }
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

@Override
public FragmentNodeInfo getFragmentNodeInfo(String sId) {
    // grab local pointers to variables subject to change at any time
    final List<FragmentDefinition> fragments = this.configurationLoader.getFragments();
    final Locale defaultLocale = LocaleManager.getPortalLocales()[0];

    final FragmentActivator activator = this.getFragmentActivator();

    final net.sf.ehcache.Element element = this.fragmentNodeInfoCache.get(sId);
    FragmentNodeInfo info = element != null ? (FragmentNodeInfo) element.getObjectValue() : null;

    if (info == null) {
        for (final FragmentDefinition fragmentDefinition : fragments) {
            final UserView userView = activator.getUserView(fragmentDefinition, defaultLocale);
            if (userView == null) {
                this.log.warn("No UserView is present for fragment " + fragmentDefinition.getName()
                        + " it will be skipped when fragment node information");
                continue;
            }/*ww w  .j  av  a  2  s . com*/

            final Element node = userView.layout.getElementById(sId);
            if (node != null) // found it
            {
                if (node.getTagName().equals(Constants.ELM_CHANNEL)) {
                    info = new FragmentChannelInfo(node);
                } else {
                    info = new FragmentNodeInfo(node);
                }
                this.fragmentNodeInfoCache.put(new net.sf.ehcache.Element(sId, info));
                break;
            }
        }
    }
    return info;
}

From source file:org.jboss.ejb3.entity.PersistenceXmlLoader.java

public static List<PersistenceMetadata> deploy(URL url, Map overrides, EntityResolver resolver,
        PersistenceUnitTransactionType defaultTransactionType) throws Exception {
    Document doc = loadURL(url, resolver);
    Element top = doc.getDocumentElement();
    NodeList children = top.getChildNodes();
    ArrayList<PersistenceMetadata> units = new ArrayList<PersistenceMetadata>();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) children.item(i);
            String tag = element.getTagName();
            if (tag.equals("persistence-unit")) {
                PersistenceMetadata metadata = parsePersistenceUnit(element, defaultTransactionType);
                //override properties of metadata if needed
                String provider = (String) overrides.get(HibernatePersistence.PROVIDER);
                if (provider != null) {
                    metadata.setProvider(provider);
                }/* w w w  .  j a va2  s  .c  om*/
                String transactionType = (String) overrides.get(HibernatePersistence.TRANSACTION_TYPE);
                if (StringHelper.isNotEmpty(transactionType)) {
                    metadata.setTransactionType(getTransactionType(transactionType));
                }
                String dataSource = (String) overrides.get(HibernatePersistence.JTA_DATASOURCE);
                if (dataSource != null) {
                    metadata.setJtaDatasource(dataSource);
                }
                dataSource = (String) overrides.get(HibernatePersistence.NON_JTA_DATASOURCE);
                if (dataSource != null) {
                    metadata.setNonJtaDatasource(dataSource);
                }
                Properties properties = metadata.getProps();
                ConfigurationHelper.overrideProperties(properties, overrides);
                units.add(metadata);
            }
        }
    }

    return units;
}

From source file:org.jboss.ejb3.entity.PersistenceXmlLoader.java

private static PersistenceMetadata parsePersistenceUnit(Element top,
        PersistenceUnitTransactionType defaultTransactionType) throws Exception {
    PersistenceMetadata metadata = new PersistenceMetadata();
    String puName = top.getAttribute("name");
    if (StringHelper.isNotEmpty(puName)) {
        log.trace("Persistent Unit name from persistence.xml: " + puName);
        metadata.setName(puName);/* w  ww  .ja  va2  s  .co m*/
    }
    PersistenceUnitTransactionType transactionType = getTransactionType(top.getAttribute("transaction-type"));
    //parsing a persistence.xml means we are in a JavaSE environment
    transactionType = transactionType != null ? transactionType : defaultTransactionType;
    metadata.setTransactionType(transactionType);
    NodeList children = top.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) children.item(i);
            String tag = element.getTagName();
            //            if ( tag.equals( "name" ) ) {
            //               String puName = XmlHelper.getElementContent( element );
            //               log.trace( "FOUND PU NAME: " + puName );
            //               metadata.setName( puName );
            //            }
            //            else
            if (tag.equals("non-jta-data-source")) {
                metadata.setNonJtaDatasource(XmlHelper.getElementContent(element));
            } else if (tag.equals("jta-data-source")) {
                metadata.setJtaDatasource(XmlHelper.getElementContent(element));
            } else if (tag.equals("provider")) {
                metadata.setProvider(XmlHelper.getElementContent(element));
            } else if (tag.equals("class")) {
                metadata.getClasses().add(XmlHelper.getElementContent(element));
            } else if (tag.equals("mapping-file")) {
                metadata.getMappingFiles().add(XmlHelper.getElementContent(element));
            } else if (tag.equals("jar-file")) {
                metadata.getJarFiles().add(XmlHelper.getElementContent(element));
            } else if (tag.equals("exclude-unlisted-classes")) {
                metadata.setExcludeUnlistedClasses(true);
            } else if (tag.equals("properties")) {
                NodeList props = element.getChildNodes();
                for (int j = 0; j < props.getLength(); j++) {
                    if (props.item(j).getNodeType() == Node.ELEMENT_NODE) {
                        Element propElement = (Element) props.item(j);
                        if (!"property".equals(propElement.getTagName()))
                            continue;
                        String propName = propElement.getAttribute("name").trim();
                        String propValue = propElement.getAttribute("value").trim();
                        if (StringHelper.isEmpty(propValue)) {
                            //fall back to the natural (Hibernate) way of description
                            propValue = XmlHelper.getElementContent(propElement, "");
                        }
                        metadata.getProps().put(propName, propValue);
                    }
                }

            }
        }
    }

    return metadata;
}

From source file:org.jboss.loom.migrators.connectionFactories.ResAdapterMigrator.java

/**
 * {@inheritDoc}// w w  w  .  ja v  a2s .c om
 */
@Override
public void loadSourceServerConfig(MigrationContext ctx) throws LoadMigrationException {
    try {

        // Deployments AS 5 dir.
        File dsFiles = getGlobalConfig().getAS5Config().getDeployDir();
        if (!dsFiles.canRead())
            throw new LoadMigrationException("Can't read: " + dsFiles.getPath());

        // -ds.xml files.
        SuffixFileFilter sf = new SuffixFileFilter("-ds.xml");
        Collection<File> dsXmls = FileUtils.listFiles(dsFiles, sf, FileFilterUtils.trueFileFilter());
        log.debug("  Found -ds.xml files #: " + dsXmls.size());
        if (dsXmls.isEmpty())
            return;

        List<ConnectionFactoriesBean> connFactories = new LinkedList();
        Unmarshaller dataUnmarshaller = JAXBContext.newInstance(ConnectionFactoriesBean.class)
                .createUnmarshaller();

        // For each -ds.xml
        for (File dsXml : dsXmls) {
            Document doc = XmlUtils.parseFileToXmlDoc(dsXml);

            Element element = doc.getDocumentElement();
            if ("connection-factories".equals(element.getTagName())) {
                ConnectionFactoriesBean conn = (ConnectionFactoriesBean) dataUnmarshaller.unmarshal(dsXml);
                connFactories.add(conn);
            }
        }

        MigratorData migrData = new MigratorData();

        for (ConnectionFactoriesBean cf : connFactories) {
            if (cf.getConnectionFactories() != null) {
                migrData.getConfigFragments().addAll(cf.getConnectionFactories());
            }
            if (cf.getNoTxConnectionFactories() != null) {
                migrData.getConfigFragments().addAll(cf.getNoTxConnectionFactories());
            }
        }

        ctx.getMigrationData().put(ResAdapterMigrator.class, migrData);

    } catch (JAXBException | SAXException | IOException e) {
        throw new LoadMigrationException(e);
    }
}

From source file:org.jboss.loom.migrators.dataSources.DatasourceMigrator.java

@Override
public void loadSourceServerConfig(MigrationContext ctx) throws LoadMigrationException {
    try {//w  w w .  j a  v a2 s.c  o m

        // Get a list of -ds.xml files.
        File dsFiles = getGlobalConfig().getAS5Config().getDeployDir();
        if (!dsFiles.canRead())
            throw new LoadMigrationException("Can't read: " + dsFiles);

        SuffixFileFilter sf = new SuffixFileFilter("-ds.xml");
        Collection<File> dsXmls = FileUtils.listFiles(dsFiles, sf, FileFilterUtils.trueFileFilter());
        log.debug("  Found -ds.xml files #: " + dsXmls.size());
        if (dsXmls.isEmpty())
            return;

        List<DatasourcesBean> dsColl = new LinkedList();
        Unmarshaller dataUnmarshaller = JAXBContext.newInstance(DatasourcesBean.class).createUnmarshaller();

        for (File dsXml : dsXmls) {
            Document doc = XmlUtils.parseFileToXmlDoc(dsXml);
            Element element = doc.getDocumentElement();
            if (DATASOURCES_ROOT_ELEMENT_NAME.equals(element.getTagName())) {
                DatasourcesBean dataSources = (DatasourcesBean) dataUnmarshaller.unmarshal(dsXml);
                dsColl.add(dataSources);
            }
        }

        MigratorData mData = new MigratorData();

        for (DatasourcesBean ds : dsColl) {
            if (ds.getLocalDatasourceAS5s() != null)
                mData.getConfigFragments().addAll(ds.getLocalDatasourceAS5s());

            if (ds.getXaDatasourceAS5s() != null)
                mData.getConfigFragments().addAll(ds.getXaDatasourceAS5s());

            if (ds.getNoTxDatasourceAS5s() != null)
                mData.getConfigFragments().addAll(ds.getNoTxDatasourceAS5s());
        }

        ctx.getMigrationData().put(DatasourceMigrator.class, mData);

    } catch (JAXBException | SAXException | IOException ex) {
        throw new LoadMigrationException(ex);
    }
}

From source file:org.jzkit.search.util.RecordModel.XMLRecord.java

private String deriveSchemaFromDoc() {
    String result = null;// w  ww.  j  a v  a2 s .com

    try {
        Document d = getDocument();
        Element root_element = d.getDocumentElement();
        String root_tag = root_element.getTagName();
        // String tag_prefix = root_element.getPrefix();
        String tag_namespace_uri = root_element.getNamespaceURI();
        // log.debug("root_tag: "+root_tag);
        // log.debug("tag_prefix: "+tag_prefix);
        // log.debug("tag_namespace_uri: "+tag_namespace_uri);

        // If tag_namespace_uri we need to resolve it into a local name and then look up a canonical single
        // name for the schema. For now, we will just default to the root tag, but that is a bit pants.
        // result = ( tag_namespace_uri != null ? tag_namespace_uri+":"+root_tag : root_tag );
        result = root_tag;
    } catch (Exception e) {
        log.debug("Problem: " + e);
    }

    return result;
}