protected Boolean readBooleanAttribute(String attributeName, Boolean defaultValue) { Node a = currentTag.getAttributes().getNamedItem(attributeName); if (a != null) { return Boolean.valueOf(a.getNodeValue()); } return defaultValue; }
private static String getAttributeValue(Node node, String attributeName) { NamedNodeMap attrs = node.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode == null) return null; else return _attributeNode.getNodeValue(); }
protected Float readFloatAttribute(String attributeName, Float defaultValue) { Node a = currentTag.getAttributes().getNamedItem(attributeName); if (a != null) { return Float.valueOf(a.getNodeValue()); } return defaultValue; }
protected String readAttribute(String attributeName, String defaultValue) { Node a = currentTag.getAttributes().getNamedItem(attributeName); if (a != null) { return a.getNodeValue(); } return defaultValue; }
/** {@inheritDoc} */ @Override protected void applyProperty(@Nonnull Node node) { String nodeName = node.getNodeName(); String nodeValue = node.getChildNodes().item(0).getNodeValue(); switch (nodeName) { case SPREADSHEET_NAME: adaptProperty(nodeValue, SPREADSHEET_NAME_KEY, SPREADSHEET_NAME_EXPRESSION_KEY); break; case WORKSHEET_NAME: adaptProperty(nodeValue, WORKSHEET_NAME_KEY, WORKSHEET_NAME_EXPRESSION_KEY); break; case FILE_PATH: adaptProperty(nodeValue, FILE_PATH_KEY, FILE_PATH_EXPRESSION_KEY); break; case BATCH_SIZE: adaptProperty(nodeValue, BATCH_SIZE_KEY, BATCH_SIZE_EXPRESSION_KEY); break; case BATCH_ENABLE: adaptProperty(nodeValue, BATCH_ENABLE_KEY, BATCH_ENABLE_EXPRESSION_KEY); break; default: } }
protected BigInteger readBigIntegerAttribute(String attributeName, BigInteger defaultValue) { Node a = currentTag.getAttributes().getNamedItem(attributeName); if (a != null) { return new BigInteger(a.getNodeValue()); } return defaultValue; }
protected Date readDateAttribute(String attributeName, Date defaultValue) { Node a = currentTag.getAttributes().getNamedItem(attributeName); if (a != null) { return new Date(Long.valueOf(a.getNodeValue())); } return defaultValue; }
protected ForeignKeySpec.ForeignKeyRule readForeignKeyRuleAttribute( String attributeName, ForeignKeySpec.ForeignKeyRule defaultValue) { try { Node a = currentTag.getAttributes().getNamedItem(attributeName); return ForeignKeySpec.ForeignKeyRule.valueOf(a.getNodeValue()); } catch (Exception ex) { return defaultValue; } }
/** {@inheritDoc} */ @Override protected void applyProperty(@Nonnull Node node) { String nodeName = node.getNodeName(); String nodeValue = node.getChildNodes().item(0).getNodeValue(); if (PROJECT_KEY.equals(nodeName)) { adaptProperty(nodeValue, PROJECT_KEY_INL, PROJECT_KEY_EXPR); } }
public void onResponseReceived(Request request, Response response) { String text = response.getText(); String url = null; Document document = null; String bpath = "<" + TAG_BLOBSTORE_PATH + ">"; String sbpath = "</" + TAG_BLOBSTORE_PATH + ">"; if (text.contains(bpath)) { try { document = XMLParser.parse(text); url = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_PATH); } catch (Exception e) { cancelUpload( i18nStrs.uploaderBlobstoreError() + "\n>>>\n" + e.getMessage() + "\n>>>>\n" + e); return; } if (url == null) { url = text.replaceAll("[\r\n]+", "") .replaceAll("^.*" + bpath + "\\s*", "") .replaceAll("\\s*" + sbpath + ".*$", ""); } } if (url != null && url.length() > 0 && !"null".equalsIgnoreCase(url)) { if (session.getServletPath().startsWith("http")) { url = session.getServletPath().replaceFirst("(https?://[^/]+).*", "$1") + url; } uploadForm.setAction(url); } else { uploadForm.setAction(session.getServletPath()); } removeHiddens(); if (document != null) { String name = Utils.getXmlNodeValue(document, TAG_BLOBSTORE_NAME); if (name != null) { fileInput.setName(name); } NodeList list = document.getElementsByTagName(TAG_BLOBSTORE_PARAM); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); String value = Utils.getXmlNodeValue(node); if (value != null) { Node attribute = node.getAttributes().getNamedItem(ATTR_BLOBSTORE_PARAM_NAME); if (attribute != null) { String paramName = attribute.getNodeValue(); if (paramName != null) { addHidden(paramName, value); } } } } } receivedBlobPath = true; uploadForm.submit(); }
@Override public void visit(Entity entity) { NamedNodeMap attrs = currentTag.getAttributes(); Node a = attrs.getNamedItem(DATASOURCE_NAME_TAG_NAME); if (a != null) { entity.setName(a.getNodeValue()); } a = attrs.getNamedItem(DATASOURCE_TITLE_TAG_NAME); if (a != null) { entity.setTitle(a.getNodeValue()); } readEntity(entity); }
public static ArrayList<String> getUsedFqnFromHits(String xmlResultInString) { ArrayList<String> usedFqns = new ArrayList<String>(); Document doc = XMLParser.parse(xmlResultInString); NodeList _arrs = doc.getElementsByTagName("arr"); for (int i = 0; i < _arrs.getLength(); i++) { Node _arr = _arrs.item(i); NamedNodeMap _nnm = _arr.getAttributes(); if (_nnm != null) { Node _nameNode = _nnm.getNamedItem("name"); if (_nameNode != null) { String _nodeType = _nameNode.getNodeValue(); if (_nodeType.equals("lib_use_fqn_full") || _nodeType.equals("jdk_use_fqn_full") || _nodeType.equals("local_use_fqn_full")) { NodeList _fqns = _arr.getChildNodes(); for (int j = 0; j < _fqns.getLength(); j++) { Node _fqn = _fqns.item(j); if (_fqn.getNodeName().equals("str")) { String _usedFqn = _fqn.getFirstChild().getNodeValue(); usedFqns.add(_usedFqn); } } } } } } return usedFqns; }
@Override public void visit(final ReferenceRelation relation) { visit((Relation) relation); NamedNodeMap attrs = currentTag.getAttributes(); Node scalarna = attrs.getNamedItem(SCALAR_PROP_NAME_ATTR_NAME); Node collectionna = attrs.getNamedItem(COLLECTION_PROP_NAME_ATTR_NAME); String scalarPropertyName = scalarna != null ? scalarna.getNodeValue() : null; ; String collectionPropertyName = collectionna != null ? collectionna.getNodeValue() : null; ; relation.setScalarPropertyName(scalarPropertyName != null ? scalarPropertyName.trim() : null); relation.setCollectionPropertyName( collectionPropertyName != null ? collectionPropertyName.trim() : null); }
private void loadSortFields(Element rootNode, HashMap<String, DisplayColumnWidget> displayCols) { NodeList nodes = rootNode.getChildNodes(); for (int index = 0; index < nodes.getLength(); index++) { Node node = nodes.item(index); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equalsIgnoreCase(XmlBuilder.NODE_NAME_FIELD)) { Element element = (Element) node; DisplayColumnWidget widget = displayCols.get(element.getAttribute(XmlBuilder.ATTRIBUTE_NAME_NAME)); int sortOrder = Integer.parseInt(element.getAttribute(XmlBuilder.ATTRIBUTE_NAME_SORT_ORDER)); widget.setSortOrder(sortOrder); changeSortOrder(widget, sortOrder); } } }
private void parseEntries(@Nonnull final Document document) { NodeList entryNodes = document.getElementsByTagName(ENTRY_TAG); if (entryNodes != null) { Node entryNode; for (int i = 0; i < entryNodes.getLength(); i++) { entryNode = entryNodes.item(i); assert entryNode != null; if (entryNode.getNodeType() == ELEMENT_NODE) { entries.add(new Entry(entryNodes.item(i))); } } Collections.reverse(entries); } }
public static ArrayList<String> getHitEidsFromHits(String xmlResultInString) { ArrayList<String> _hitEids = new ArrayList<String>(); Document doc = XMLParser.parse(xmlResultInString); NodeList hits = doc.getElementsByTagName("doc"); for (int i = 0; i < hits.getLength(); i++) { Node hit = hits.item(i); NodeList hitDocChildNodes = hit.getChildNodes(); String entity_id = ""; for (int j = 0; j < hitDocChildNodes.getLength(); j++) { Node hitDocChildNode = hitDocChildNodes.item(j); NamedNodeMap attrs = hitDocChildNode.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals("entity_id")) { entity_id = hitDocChildNode.getFirstChild().getNodeValue(); } } } _hitEids.add(entity_id); } return _hitEids; }
@Override public void visit(final Relation relation) { if (relation != null && model != null) { NamedNodeMap attrs = currentTag.getAttributes(); Node lefna = attrs.getNamedItem(LEFT_ENTITY_FIELD_ATTR_NAME); Node lepna = attrs.getNamedItem(LEFT_ENTITY_PARAMETER_ATTR_NAME); Node refna = attrs.getNamedItem(RIGHT_ENTITY_FIELD_ATTR_NAME); Node repna = attrs.getNamedItem(RIGHT_ENTITY_PARAMETER_ATTR_NAME); final String leftEntityId = readAttribute(LEFT_ENTITY_ID_ATTR_NAME, null); final String leftFieldName = lefna != null ? lefna.getNodeValue() : null; final String leftParameterName = lepna != null ? lepna.getNodeValue() : null; final String rightEntityId = readAttribute(RIGHT_ENTITY_ID_ATTR_NAME, null); final String rightFieldName = refna != null ? refna.getNodeValue() : null; final String rightParameterName = repna != null ? repna.getNodeValue() : null; model.addRelation(relation); Runnable resolver = new Runnable() { @Override public void run() { try { Entity lEntity = model.getEntityById(leftEntityId); if (lEntity != null) { if (leftParameterName != null && !leftParameterName.isEmpty()) { relation.setLeftField( lEntity.getQuery().getParameters().get(leftParameterName)); } else if (leftFieldName != null && !leftFieldName.isEmpty()) { relation.setLeftField(lEntity.getFields().get(leftFieldName)); } } relation.setLeftEntity(lEntity); lEntity.addOutRelation(relation); Entity rEntity = model.getEntityById(rightEntityId); if (rEntity != null) { if (rightParameterName != null && !rightParameterName.isEmpty()) { relation.setRightField( rEntity.getQuery().getParameters().get(rightParameterName)); } else if (rightFieldName != null && !rightFieldName.isEmpty()) { relation.setRightField(rEntity.getFields().get(rightFieldName)); } } relation.setRightEntity(rEntity); rEntity.addInRelation(relation); } catch (Exception ex) { Logger.getLogger(XmlDom2Model.class.getName()).log(Level.SEVERE, null, ex); } } }; relationsResolvers.add(resolver); } }
private HashMap<String, DisplayColumnWidget> loadDisplayFields( Element rootNode, HashMap<String, DisplayColumnWidget> displayCols) { NodeList nodes = rootNode.getChildNodes(); for (int index = 0; index < nodes.getLength(); index++) { Node node = nodes.item(index); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equalsIgnoreCase(XmlBuilder.NODE_NAME_FIELD)) { Element element = (Element) node; DisplayColumnWidget widget = addColumn(this); widget.setName(element.getAttribute(XmlBuilder.ATTRIBUTE_NAME_NAME)); widget.setText(element.getAttribute(XmlBuilder.ATTRIBUTE_NAME_TEXT)); widget.setAggregateFunction(element.getAttribute(XmlBuilder.ATTRIBUTE_NAME_AGG_FUNC)); displayCols.put(widget.getName(), widget); } } return displayCols; }
private static Node getResponseNode(String xmlResultInString) { Document doc = XMLParser.parse(xmlResultInString); NodeList results = doc.getElementsByTagName("result"); for (int i = 0; i < results.getLength(); i++) { Node result = results.item(i); NamedNodeMap attrs = result.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals("response")) { return result; } } } return null; }
private void visit(PrimaryKeySpec pk) { if (pk != null) { NamedNodeMap attrs = currentTag.getAttributes(); Node a = attrs.getNamedItem(CONSTRAINT_NAME_ATTR_NAME); if (a != null) { pk.setCName(a.getNodeValue()); } a = attrs.getNamedItem(CONSTRAINT_SCHEMA_ATTR_NAME); if (a != null) { pk.setSchema(a.getNodeValue()); } a = attrs.getNamedItem(CONSTRAINT_TABLE_ATTR_NAME); if (a != null) { pk.setTable(a.getNodeValue()); } a = attrs.getNamedItem(CONSTRAINT_FIELD_ATTR_NAME); if (a != null) { pk.setField(a.getNodeValue()); } } }
/** * Check to ensure that a Docbook tgroup isn't missing an row entries, using number of cols * defined for the tgroup. * * @param tgroup The DOM tgroup element to be checked. * @return True if the tgroup has the required number of entries, otherwise false. */ public static boolean validateTableGroup(final Element tgroup) { assert tgroup != null; assert tgroup.getNodeName().equals("tgroup"); final Integer numColumns = Integer.parseInt(tgroup.getAttribute("cols")); // Check that all the thead, tbody and tfoot elements have the correct number of entries. final List<Node> nodes = XMLUtilities.getDirectChildNodes(tgroup, "thead", "tbody", "tfoot"); for (final Node ele : nodes) { // Find all child nodes that are a row final NodeList children = ele.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node node = children.item(i); if (node.getNodeName().equals("row") || node.getNodeName().equals("tr")) { if (!validateTableRow(node, numColumns)) return false; } } } return true; }
/** * Check to ensure that a docbook row has the required number of columns for a table. * * @param row The DOM row element to be checked. * @param numColumns The number of entry elements that should exist in the row. * @return True if the row has the required number of entries, otherwise false. */ public static boolean validateTableRow(final Node row, final int numColumns) { assert row != null; assert row.getNodeName().equals("row") || row.getNodeName().equals("tr"); if (row.getNodeName().equals("row")) { final List<Node> entries = XMLUtilities.getDirectChildNodes(row, "entry"); final List<Node> entryTbls = XMLUtilities.getDirectChildNodes(row, "entrytbl"); if ((entries.size() + entryTbls.size()) <= numColumns) { for (final Node entryTbl : entryTbls) { if (!validateEntryTbl((Element) entryTbl)) return false; } return true; } else { return false; } } else { final List<Node> nodes = XMLUtilities.getDirectChildNodes(row, "td", "th"); return nodes.size() <= numColumns; } }
public static String getXmlNodeValue(Node node) { if (node.getNodeType() != Node.ELEMENT_NODE) { return null; } String ret = ""; NodeList textNodes = node.getChildNodes(); for (int i = 0; i < textNodes.getLength(); i++) { Node n = textNodes.item(i); if (n.getNodeType() == Node.TEXT_NODE && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0) { ret += n.getNodeValue(); } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) { ret += n.getNodeValue(); } } return ret.length() == 0 ? null : ret.replaceAll("^\\s+", "").replaceAll("\\s+$", ""); }
public static List<HitFqnEntityId> getUsedApisFromFacetedHits( String xmlResultInString, EntityCategory c) { // if (c.equals(EntityCategory.LOCAL)) // throw new IllegalArgumentException("only jdk or lib"); List<HitFqnEntityId> apis = new LinkedList<HitFqnEntityId>(); Document doc = XMLParser.parse(xmlResultInString); NodeList apisNodes = doc.getElementsByTagName("lst"); String nodeName; if (c.equals(EntityCategory.JDK)) nodeName = "jdk_use_fqn_full"; else if (c.equals(EntityCategory.LIB)) nodeName = "lib_use_fqn_full"; else return apis; for (int i = 0; i < apisNodes.getLength(); i++) { Node apiNode = apisNodes.item(i); NamedNodeMap attrs = apiNode.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals(nodeName)) { // iterate through int nodes NodeList fqnNodes = apiNode.getChildNodes(); for (int j = 0; j < fqnNodes.getLength(); j++) { Node fqnNode = fqnNodes.item(j); if (fqnNode.getNodeName().equals("int")) { String fqn = getAttributeValue(fqnNode, "name"); if (fqn != null) { String count = fqnNode.getFirstChild().getNodeValue(); HitFqnEntityId _apiFqn = new HitFqnEntityId(fqn, "-1", count); apis.add(_apiFqn); } } } } } } return apis; }
/** return the text content of a tag in a xml document. */ public static String getXmlNodeValue(Document doc, String tag) { if (doc == null) return null; NodeList list = doc.getElementsByTagName(tag); if (list.getLength() == 0) return null; Node node = list.item(0); if (node.getNodeType() != Node.ELEMENT_NODE) return null; String ret = ""; NodeList textNodes = node.getChildNodes(); for (int i = 0; i < textNodes.getLength(); i++) { Node n = textNodes.item(i); if (n.getNodeType() == Node.TEXT_NODE && n.getNodeValue().replaceAll("[ \\n\\t\\r]", "").length() > 0) ret += n.getNodeValue(); } return ret.length() == 0 ? null : ret; }
public static HitsStat getStatsFromHits(String xmlResultInString) { long start = 0; long numResults = 0; double timeTaken = 0; Node responseNode = getResponseNode(xmlResultInString); if (responseNode == null) return null; NamedNodeMap attrs = responseNode.getAttributes(); Node _numFoundNode = attrs.getNamedItem("numFound"); Node _startNode = attrs.getNamedItem("start"); if (_numFoundNode != null) { numResults = Long.parseLong(_numFoundNode.getNodeValue()); } if (_startNode != null) { start = Long.parseLong(_startNode.getNodeValue()); } return new HitsStat(start, numResults, timeTaken); }
public static List<HitFqnEntityId> getFqnEntityIdFromHits(String xmlResultInString) { List<HitFqnEntityId> hitsInfo = new LinkedList<HitFqnEntityId>(); Node responseNode = getResponseNode(xmlResultInString); NodeList hits = responseNode.getChildNodes(); for (int i = 0; i < hits.getLength(); i++) { String fqn = ""; String entity_id = ""; Node hit = hits.item(i); if (!hit.getNodeName().equals("doc")) continue; NodeList hitDocChildNodes = hit.getChildNodes(); for (int j = 0; j < hitDocChildNodes.getLength(); j++) { Node hitDocChildNode = hitDocChildNodes.item(j); NamedNodeMap attrs = hitDocChildNode.getAttributes(); Node _attributeNode = null; _attributeNode = attrs.getNamedItem("name"); if (_attributeNode != null) { if (_attributeNode.getNodeValue().equals("entity_id")) { entity_id = hitDocChildNode.getFirstChild().getNodeValue(); } else if (_attributeNode.getNodeValue().equals("fqn_full")) { fqn = hitDocChildNode.getFirstChild().getNodeValue(); } } } hitsInfo.add(new HitFqnEntityId(fqn, entity_id)); } return hitsInfo; }
@Override public void visit(Field aField) { try { NamedNodeMap attrs = currentTag.getAttributes(); Node a = attrs.getNamedItem(NAME_ATTR_NAME); if (a != null) { aField.setName(a.getNodeValue()); } a = attrs.getNamedItem(DESCRIPTION_ATTR_NAME); if (a != null) { aField.setDescription(a.getNodeValue()); } a = attrs.getNamedItem(TYPE_ATTR_NAME); if (a != null) { aField.setType(a.getNodeValue()); } aField.setNullable(readBooleanAttribute(NULLABLE_ATTR_NAME, true)); aField.setPk(readBooleanAttribute(IS_PK_ATTR_NAME, false)); if (aField instanceof Parameter) { ((Parameter) aField).setMode(readIntegerAttribute(MODE_ATTR_NAME, 0 /* * ParameterMetaData. * parameterModeUnknown */)); if (currentTag.getAttributes().getNamedItem(SELECTION_FORM_TAG_NAME) != null && !"null" .equals( currentTag .getAttributes() .getNamedItem(SELECTION_FORM_TAG_NAME) .getNodeValue())) ((Parameter) aField).setSelectionForm(readDoubleAttribute(SELECTION_FORM_TAG_NAME, null)); } Element lcurrentTag = currentTag; try { currentTag = Utils.getElementByTagName(currentTag, PRIMARY_KEY_TAG_NAME); if (currentTag != null) { PrimaryKeySpec pk = new PrimaryKeySpec(); visit(pk); ForeignKeySpec fk = new ForeignKeySpec( "", "", "", "", ForeignKeySpec.ForeignKeyRule.CASCADE, ForeignKeySpec.ForeignKeyRule.CASCADE, false, pk.getSchema(), pk.getTable(), pk.getField(), pk.getCName()); aField.setFk(fk); } } finally { currentTag = lcurrentTag; } } catch (NumberFormatException ex) { Logger.getLogger(XmlDom2Model.class.getName()).log(Level.SEVERE, null, ex); } }