コード例 #1
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
  @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);
    }
  }
コード例 #2
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 @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);
 }
コード例 #3
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
  @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);
  }
コード例 #4
0
 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();
 }
コード例 #5
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 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;
 }
コード例 #6
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 protected String readAttribute(String attributeName, String defaultValue) {
   Node a = currentTag.getAttributes().getNamedItem(attributeName);
   if (a != null) {
     return a.getNodeValue();
   }
   return defaultValue;
 }
コード例 #7
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 protected BigInteger readBigIntegerAttribute(String attributeName, BigInteger defaultValue) {
   Node a = currentTag.getAttributes().getNamedItem(attributeName);
   if (a != null) {
     return new BigInteger(a.getNodeValue());
   }
   return defaultValue;
 }
コード例 #8
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 protected Boolean readBooleanAttribute(String attributeName, Boolean defaultValue) {
   Node a = currentTag.getAttributes().getNamedItem(attributeName);
   if (a != null) {
     return Boolean.valueOf(a.getNodeValue());
   }
   return defaultValue;
 }
コード例 #9
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 protected Float readFloatAttribute(String attributeName, Float defaultValue) {
   Node a = currentTag.getAttributes().getNamedItem(attributeName);
   if (a != null) {
     return Float.valueOf(a.getNodeValue());
   }
   return defaultValue;
 }
コード例 #10
0
  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;
  }
コード例 #11
0
  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;
  }
コード例 #12
0
ファイル: Utils.java プロジェクト: stsypanov/gwtupload
 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+$", "");
 }
コード例 #13
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 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;
   }
 }
コード例 #14
0
ファイル: IUploader.java プロジェクト: stephenh/gwtupload
    /** 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;
    }
コード例 #15
0
ファイル: Uploader.java プロジェクト: cyrilmhansen/gwtupload
        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();
        }
コード例 #16
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
 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());
     }
   }
 }
コード例 #17
0
  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);
  }
コード例 #18
0
  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;
  }
コード例 #19
0
  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;
  }
コード例 #20
0
  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;
  }
コード例 #21
0
ファイル: XmlDom2Model.java プロジェクト: cbsistem/PlatypusJS
  @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);
    }
  }