List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:org.glom.app.libglom.Document.java
public boolean load(final InputStream inputStream) { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; try {//from ww w . j a v a 2 s . c o m documentBuilder = dbf.newDocumentBuilder(); } catch (final ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } org.w3c.dom.Document xmlDocument; try { xmlDocument = documentBuilder.parse(inputStream); } catch (final SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } final Element rootNode = xmlDocument.getDocumentElement(); if (!TextUtils.equals(rootNode.getNodeName(), NODE_ROOT)) { Log.v("android-glom", "Unexpected XML root node name found: " + rootNode.getNodeName()); return false; } //Get the database title, falling back to the deprecated XML format for it: //TODO: load() show complain (via an enum result) if the document format version is less than 7. final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE); final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE); if (!TextUtils.isEmpty(databaseTitleStr)) { databaseTitle.setTitleOriginal(databaseTitleStr); } else { databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr); } loadTitle(rootNode, databaseTitle); translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE); translationAvailableLocales.add(translationOriginalLocale); // Just a cache. isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE); final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION); if (nodeConnection != null) { final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE); switch (strHostingMode) { case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL; break; case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; break; case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL: hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL; break; case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF: hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF; break; case ATTRIBUTE_CONNECTION_HOSTING_SQLITE: hostingMode = HostingMode.HOSTING_MODE_SQLITE; break; default: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; break; } connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER); connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE); connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT); } // We first load the fields, relationships, etc, // for all tables: final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE); for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final TableInfo info = loadTableNodeBasic(element); tablesMap.put(info.getName(), info); } // We then load the layouts for all tables, because they // need the fields and relationships for all tables: for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final String tableName = element.getAttribute(ATTRIBUTE_NAME); // We first load the fields, relationships, etc: final TableInfo info = getTableInfo(tableName); if (info == null) { continue; } // We then load the layouts afterwards, because they // need the fields and relationships: loadTableLayouts(element, info); tablesMap.put(info.getName(), info); } return true; }
From source file:org.glom.libglom.Document.java
public boolean load(final InputStream inputStream) { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder; try {/*from w ww.jav a 2s .co m*/ documentBuilder = dbf.newDocumentBuilder(); } catch (final ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } org.w3c.dom.Document xmlDocument; try { xmlDocument = documentBuilder.parse(inputStream); } catch (final SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } final Element rootNode = xmlDocument.getDocumentElement(); if (!StringUtils.equals(rootNode.getNodeName(), NODE_ROOT)) { Logger.log("Unexpected XML root node name found: " + rootNode.getNodeName()); return false; } //Get the database title, falling back to the deprecated XML format for it: //TODO: load() show complain (via an enum result) if the document format version is less than 7. final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE); final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE); if (!StringUtils.isEmpty(databaseTitleStr)) { databaseTitle.setTitleOriginal(databaseTitleStr); } else { databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr); } loadTitle(rootNode, databaseTitle); translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE); translationAvailableLocales.add(translationOriginalLocale); // Just a cache. isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE); final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION); if (nodeConnection != null) { final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE); switch (strHostingMode) { case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL; break; case ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; break; case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL: hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL; break; case ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF: hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF; break; case ATTRIBUTE_CONNECTION_HOSTING_SQLITE: hostingMode = HostingMode.HOSTING_MODE_SQLITE; break; default: hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; break; } connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER); connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE); connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT); } // We first load the fields, relationships, etc, // for all tables: final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE); for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final TableInfo info = loadTableNodeBasic(element); tablesMap.put(info.getName(), info); } // We then load the layouts for all tables, because they // need the fields and relationships for all tables: for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final String tableName = element.getAttribute(ATTRIBUTE_NAME); // We first load the fields, relationships, etc: final TableInfo info = getTableInfo(tableName); if (info == null) { continue; } // We then load the layouts afterwards, because they // need the fields and relationships: loadTableLayouts(element, info); tablesMap.put(info.getName(), info); } return true; }
From source file:org.glom.web.server.libglom.Document.java
public boolean load() { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; try {/*from w w w .ja v a 2 s . c o m*/ documentBuilder = dbf.newDocumentBuilder(); } catch (final ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } try { xmlDocument = documentBuilder.parse(fileURI); } catch (final SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } final Element rootNode = xmlDocument.getDocumentElement(); if (rootNode.getNodeName() != NODE_ROOT) { Log.error("Unexpected XML root node name found: " + rootNode.getNodeName()); return false; } //Get the database title, falling back to the deprecated XML format for it: //TODO: load() show complain (via an enum result) if the document format version is less than 7. final String databaseTitleStr = rootNode.getAttribute(ATTRIBUTE_TITLE); final String deprecatedDatabaseTitleStr = rootNode.getAttribute(DEPRECATED_ATTRIBUTE_DATABASE_TITLE); if (!StringUtils.isEmpty(databaseTitleStr)) { databaseTitle.setTitleOriginal(databaseTitleStr); } else { databaseTitle.setTitleOriginal(deprecatedDatabaseTitleStr); } loadTitle(rootNode, databaseTitle); translationOriginalLocale = rootNode.getAttribute(ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE); translationAvailableLocales.add(translationOriginalLocale); // Just a cache. isExample = getAttributeAsBoolean(rootNode, ATTRIBUTE_IS_EXAMPLE); final Element nodeConnection = getElementByName(rootNode, NODE_CONNECTION); if (nodeConnection != null) { final String strHostingMode = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_HOSTING_MODE); if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_CENTRAL)) { hostingMode = HostingMode.HOSTING_MODE_POSTGRES_CENTRAL; } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_POSTGRES_SELF)) { hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_MYSQL_CENTRAL)) { hostingMode = HostingMode.HOSTING_MODE_MYSQL_CENTRAL; } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_MYSQL_SELF)) { hostingMode = HostingMode.HOSTING_MODE_MYSQL_SELF; } else if (strHostingMode.equals(ATTRIBUTE_CONNECTION_HOSTING_SQLITE)) { hostingMode = HostingMode.HOSTING_MODE_SQLITE; } else { hostingMode = HostingMode.HOSTING_MODE_POSTGRES_SELF; } connectionServer = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_SERVER); connectionDatabase = nodeConnection.getAttribute(ATTRIBUTE_CONNECTION_DATABASE); connectionPort = (int) getAttributeAsDecimal(nodeConnection, ATTRIBUTE_CONNECTION_PORT); } // We first load the fields, relationships, etc, // for all tables: final List<Node> listTableNodes = getChildrenByTagName(rootNode, NODE_TABLE); for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final TableInfo info = loadTableNodeBasic(element); tablesMap.put(info.getName(), info); } // We then load the layouts for all tables, because they // need the fields and relationships for all tables: for (final Node node : listTableNodes) { if (!(node instanceof Element)) { continue; } final Element element = (Element) node; final String tableName = element.getAttribute(ATTRIBUTE_NAME); // We first load the fields, relationships, etc: final TableInfo info = getTableInfo(tableName); if (info == null) { continue; } // We then load the layouts afterwards, because they // need the fields and relationships: loadTableLayouts(element, info); tablesMap.put(info.getName(), info); } return true; }
From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.PomReader.java
/** * Parses all active profiles that can be found in POM. * * @return Active POM profiles/*ww w. ja v a 2s . co m*/ */ private List<PomProfile> parseActivePomProfiles() { if (declaredActivePomProfiles == null) { List<PomProfile> activeByDefaultPomProfiles = new ArrayList<PomProfile>(); List<PomProfile> activeByAbsenceOfPropertyPomProfiles = new ArrayList<PomProfile>(); Element profilesElement = getFirstChildElement(projectElement, PROFILES); if (profilesElement != null) { for (Element profileElement : getAllChilds(profilesElement)) { if (PROFILE.equals(profileElement.getNodeName())) { Element activationElement = getFirstChildElement(profileElement, PROFILE_ACTIVATION); if (activationElement != null) { String activeByDefault = getFirstChildText(activationElement, PROFILE_ACTIVATION_ACTIVE_BY_DEFAULT); if (activeByDefault != null && "true".equals(activeByDefault)) { activeByDefaultPomProfiles.add(new PomProfileElement(profileElement)); } else { Element propertyElement = getFirstChildElement(activationElement, PROFILE_ACTIVATION_PROPERTY); if (propertyElement != null) { if (isActivationPropertyActivated(propertyElement)) { activeByAbsenceOfPropertyPomProfiles .add(new PomProfileElement(profileElement)); } } } } } } } declaredActivePomProfiles = determineActiveProfiles(activeByDefaultPomProfiles, activeByAbsenceOfPropertyPomProfiles); } return declaredActivePomProfiles; }
From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.PomReader.java
private Map<String, String> getPomProperties(Element parentElement) { Map<String, String> pomProperties = new HashMap<String, String>(); Element propsEl = getFirstChildElement(parentElement, PROPERTIES); if (propsEl != null) { propsEl.normalize();//from ww w . j a va 2 s. c om } for (Element prop : getAllChilds(propsEl)) { pomProperties.put(prop.getNodeName(), getTextContent(prop)); } return pomProperties; }
From source file:org.gradle.build.docs.dsl.docbook.JavadocConverter.java
private void adjustAccessorComment(DocCommentImpl docComment) { // Replace 'Returns the ...'/'Sets the ...' with 'The ...' List<Element> nodes = docComment.getDocbook(); if (nodes.isEmpty()) { return;/*from w ww .ja v a 2 s. c om*/ } Element firstNode = nodes.get(0); if (!firstNode.getNodeName().equals("para") || !(firstNode.getFirstChild() instanceof Text)) { return; } Text comment = (Text) firstNode.getFirstChild(); Matcher matcher = ACCESSOR_COMMENT_PATTERN.matcher(comment.getData()); if (matcher.lookingAt()) { String theOrWhether = matcher.group(1).toLowerCase(Locale.US); comment.setData( StringUtils.capitalize(theOrWhether) + " " + comment.getData().substring(matcher.end())); } }
From source file:org.gvnix.web.menu.roo.addon.MenuEntryOperationsImpl.java
/** {@inheritDoc} */ public String addMenuItem(JavaSymbolName menuCategoryName, JavaSymbolName menuItemId, String menuItemLabel, String globalMessageCode, String link, String idPrefix, String roles, boolean hide, boolean writeProps) { Validate.notNull(menuCategoryName, "Menu category name required"); Validate.notNull(menuItemId, "Menu item name required"); // Properties to be written Map<String, String> properties = new HashMap<String, String>(); if (idPrefix == null || idPrefix.length() == 0) { idPrefix = MenuOperations.DEFAULT_MENU_ITEM_PREFIX; }/*w w w . ja v a 2 s .co m*/ Document document = getMenuDocument(); // make the root element of the menu the one with the menu identifier // allowing for different decorations of menu Element rootElement = XmlUtils.findFirstElement(ID_MENU_EXP, (Element) document.getFirstChild()); if (!rootElement.getNodeName().equals(GVNIX_MENU)) { throw new IllegalArgumentException(INVALID_XML); } // build category name and Id: // - menuCategoryName is a name if it doesn't start with c_: create the // id // - menuCategoryName is an identifier if it starts with c_: create the // name String categoryName = menuCategoryName.getSymbolName(); StringBuilder categoryId = new StringBuilder(); Element category = null; // check for existence of menu category by looking for the // identifier // provided // build category name and Id: // - menuCategoryName is a name if it doesn't start with c_: create // the // id // - menuCategoryName is an identifier if it starts with c_: create // the name // don't create any categoryId if there is already an id prefix if (!categoryName.startsWith(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX) && !categoryName.startsWith(idPrefix)) { // create categoryId using the category name categoryId.append(MenuEntryOperations.CATEGORY_MENU_ITEM_PREFIX).append(categoryName.toLowerCase()); } else { categoryId.append(categoryName.toLowerCase()); // create category name using the category Id categoryName = StringUtils.capitalize(categoryName.substring(2)); } List<Element> givenCategory = XmlUtils.findElements(ID_EXP.concat(categoryId.toString()).concat("']"), rootElement); // if given category not exists, create new one if (givenCategory.isEmpty()) { String categoryLabelCode = "menu_category_".concat(categoryName.toLowerCase()).concat("_label"); category = (Element) rootElement.appendChild(new XmlElementBuilder(MENU_ITEM, document) .addAttribute("id", categoryId.toString()).addAttribute("name", categoryName) .addAttribute(LABEL_CODE, categoryLabelCode).build()); properties.put(categoryLabelCode, menuCategoryName.getReadableSymbolName()); } else { category = givenCategory.get(0); } // build menu item Id: // - if menu item id starts with 'i_', it is a valid ID but we remove // 'i_' for convenience // - otherwise, have to compose the ID StringBuilder itemId = new StringBuilder(); if (menuItemId.getSymbolName().toLowerCase().startsWith(idPrefix)) { itemId.append(menuItemId.getSymbolName().toLowerCase()); itemId.delete(0, idPrefix.length()); } else { itemId.append(categoryName.toLowerCase()).append("_").append(menuItemId.getSymbolName().toLowerCase()); } // check for existence of menu item by looking for the identifier // provided // Note that in view files, menu item ID has idPrefix_, but it doesn't // have // at application.properties, so we have to add idPrefix_ to look for // the given menu item but we have to add without idPrefix_ to // application.properties List<Element> menuList = XmlUtils .findElements(ID_EXP.concat(idPrefix).concat(itemId.toString()).concat("']"), rootElement); String itemLabelCode = "menu_item_".concat(itemId.toString()).concat("_label"); if (menuList.isEmpty()) { Element menuItem = new XmlElementBuilder(MENU_ITEM, document) .addAttribute("id", idPrefix.concat(itemId.toString())).addAttribute(LABEL_CODE, itemLabelCode) .addAttribute(MESSAGE_CODE, StringUtils.isNotBlank(globalMessageCode) ? globalMessageCode : "") .addAttribute(URL, StringUtils.isNotBlank(link) ? link : "") .addAttribute(HIDDEN, Boolean.toString(hide)) .addAttribute("roles", StringUtils.isNotBlank(roles) ? roles : "").build(); // TODO: gvnix*.tagx uses destination in spite of url, change to url category.appendChild(menuItem); } if (StringUtils.isNotBlank(menuItemLabel)) { properties.put(itemLabelCode, menuItemLabel); } if (writeProps) { propFileOperations.addProperties(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), "/WEB-INF/i18n/application.properties", properties, true, false); } writeXMLConfigIfNeeded(document); // return the ID assigned to new entry return idPrefix.concat(itemId.toString()); }
From source file:org.gvnix.web.screen.roo.addon.SeleniumServicesImpl.java
/** * Get template html content and update with current name. * /*from w w w . j a v a 2 s. c o m*/ * @param name Name to write into html content * @param document Document to write into * @return Html element with required name */ protected Element getHtmlElement(String name, Document document) { Element root = (Element) document.getLastChild(); if (root == null || !"html".equals(root.getNodeName())) { throw new IllegalArgumentException("Could not parse selenium test case template file!"); } XmlUtils.findRequiredElement("/html/head/title", root).setTextContent(name); XmlUtils.findRequiredElement("/html/body/table/thead/tr/td", root).setTextContent(name); return root; }
From source file:org.gvnix.web.theme.roo.addon.Theme.java
/** * @param themeEl//from ww w .j a v a 2s . c om */ private Theme(Element themeEl) { // if root element isn't theme, we found invalid theme if (!themeEl.getNodeName().equals("gvnix-theme")) { throw new IllegalArgumentException("Given theme Element hasn't valid XML structure."); } this.id = themeEl.getAttribute("id"); Validate.notNull(id, "Theme element must have id attribute"); Validate.notBlank(id, "Theme element must have id attribute"); this.name = themeEl.getAttribute("name"); // Description can be null in custom project themes Element themeDescription = DomUtils.findFirstElementByName("description", themeEl); this.description = themeDescription != null ? themeDescription.getTextContent() : null; // Properties can be null Element properties = DomUtils.findFirstElementByName("properties", themeEl); if (properties != null) { propertyBundles = parseThemeProperties(properties); } }
From source file:org.gvnix.web.theme.roo.addon.Theme.java
/** * Parses and build Document from the stream to Theme object. * <p>//from w ww . ja va 2s. c om * This is an internal utility method, use {@link parseTheme} and * {@link XmlUtils#parseTheme(URL)} to parse Theme descriptors because the * URI to the theme descriptor is set in the new Theme objet. * * @param is InputStream to parse * @return Theme object. Null if there is any problem parsing the stream or * the stream doesn't contain a valid XML. */ public static Theme parseTheme(InputStream is) { try { // load the theme Document themeDoc = org.springframework.roo.support.util.XmlUtils.getDocumentBuilder().parse(is); Element root = (Element) themeDoc.getDocumentElement(); // if root element isn't theme, we found invalid theme if (!root.getNodeName().equals("gvnix-theme")) { throw new IllegalStateException("XML doesn't contain valid Theme."); } Theme theme = new Theme(root); return theme; } catch (Exception e) { throw new IllegalStateException("Error parsing XML", e); } finally { IOUtils.closeQuietly(is); } }