Package org.cfeclipse.cfml.parser.docitems

Examples of org.cfeclipse.cfml.parser.docitems.TagItem


    insightXML += "\t\t\t\t]]></help>\n";
    CFNodeList args = functionTag.selectNodes("//argument");
    Iterator j = args.iterator();
    while(j.hasNext()) {
      try {
        TagItem thisArg = (TagItem)j.next();
        insightXML += "\t\t\t\t<parameter name=\""+thisArg.getAttributeValue("name") + "\" type=\"" + thisArg.getAttributeValue("type") + "\" required=\"" + thisArg.getAttributeValue("required") +"\">\n";
        insightXML += "\t\t\t\t\t<help><![CDATA[\n";
        insightXML += "\t\t\t\t\t\t" + thisArg.getAttributeValue("hint")+ "\n";
        insightXML += "\t\t\t\t\t]]></help>\n";
        insightXML += "\t\t\t\t</parameter>\n\n";
      }
      catch (Exception e) {
        //System.err.println(e.getMessage());
View Full Code Here


    CFNodeList scriptNodes = getDocumentRoot().selectNodes("//ASTFunctionDeclaration");
    Iterator i = nodes.iterator();
    Set<Function> functions = new HashSet<Function>();
    pattern = Pattern.compile("(\\w+)[\\s=]+(((\\x22|\\x27)((?!\\4).|\\4{2})*\\4))", Pattern.CASE_INSENSITIVE);
    while (i.hasNext()) {
      TagItem currItem = (TagItem) i.next();
      String funcName = currItem.getAttributeValue("name", "unnamed");
      String funcReturn = currItem.getAttributeValue("returntype", "any");

      Function function = new Function(funcName, funcReturn, Byte.parseByte("8"));
      // System.out.println(currItem.getItemData());
      if (currItem.hasChildren() && currItem.getFirstChild().getName().equals("cfargument")) {
        Iterator childNodes = currItem.getChildNodes().iterator();
        DocItem childNode;
        while (childNodes.hasNext()) {
          childNode = (DocItem) childNodes.next();
          if (childNode.getName().equals("cfargument")) {
            matcher = pattern.matcher(childNode.getItemData());
            while (matcher.find()) {
              String value = matcher.group(2).replaceAll("'", "").replaceAll("\"", "");
              if (matcher.group(1).toLowerCase().equals("name")) {
                name = value;
              }
              if (matcher.group(1).toLowerCase().equals("type")) {
                type = value;
              }
              if (matcher.group(1).toLowerCase().equals("required")) {
                required = value;
              }
              if (matcher.group(1).toLowerCase().equals("default")) {
                defaultvalue = value;
              }
            }
            Parameter newParam = new Parameter(name, type, Boolean.valueOf(required), defaultvalue);
            name = type = required = defaultvalue = "";
            function.addParameter(newParam);
          }

        }
      }
      functions.add(function);
    }
    i = scriptNodes.iterator();
    while (i.hasNext()) {
      FunctionInfo currItem = (FunctionInfo) i.next();
      String funcName = currItem.getFunctionName();
      String funcReturn = currItem.getReturnType();
      Function function = new Function(funcName, funcReturn, Byte.parseByte("8"));
      // System.out.println(currItem.getItemData());
      List args = currItem.getParameters();
      Iterator j = args.iterator();
      while (j.hasNext()) {
        Map<String, String> parameterAttribs = (Map) j.next();
        name = parameterAttribs.get("name");
        type = parameterAttribs.get("type");
View Full Code Here

      CFCMethodViewItem[] methods = new CFCMethodViewItem[nodes.size()];
      int index = 0;
      while(i.hasNext())
      {
        try {
          TagItem thisTag = (TagItem)i.next();
         
          CFCMethodViewItem item = new CFCMethodViewItem(thisTag);
         
          boolean addItem = true; // Can later use this to filter methods
         
View Full Code Here

          ArrayList removals = new ArrayList();
          Object[] items = matchStack.toArray();
          //System.out.println("Looking on stack for opening " + closerName + ". Closer found on line: " + this.getLineNumber(match.getStartPos()));
          for (int i=items.length-1;i>0;i--) {
              if (items[i] instanceof TagItem) {
                  TagItem item = (TagItem)items[i];
                  //System.out.println("Checking " + item.getName());
               
                if (item.getName().equalsIgnoreCase(closerName)) {
                    //System.out.println("Found opener. Exiting loop.");
                    foundCloser = true;
                    break;
                } else if (item.isHybrid()) {
                    removals.add(item);
                }
              }
          }
          // If we found a closer, we want to remove any unclosed hybrids.
          if (foundCloser) {
     
              items = removals.toArray();
                DocItem parent = (DocItem)matchStack.get(items.length);
              for (int i=0;i<items.length;i++) {
                  TagItem item = (TagItem)items[i];
                  //System.out.println(item.getChildNodes().size() + " children need to be moved to " + parent.getName());
                  Object[] orphans = item.getChildNodes().toArray();
                  if (item instanceof CfmlCustomTag) {
                    ((CfmlCustomTag)item).hasCloser = false;
                    parent.addChild(item);
                    item.setParent(parent);
                  }
                  for (int j=0;j<orphans.length;j++) {
                      DocItem orphan = (DocItem)orphans[j];
                      //System.out.println("Moving " + orphan.getName() + " under " + parent.getName());
                      parent.addChild(orphan);
                      item.removeChild(orphan);
                  }
                  //System.out.println("Removing " + ((TagItem)items[i]).getName() + " from the stack." + " Current parent is " + parent.getName());
                  matchStack.remove(items[i]);
              }
             
              Iterator iter = parent.getChildNodes().iterator();
              while (iter.hasNext()) {
                DocItem di = (DocItem)iter.next();
                //System.out.println("Child: " + di.getName());
              }
          }
          else {
              //System.out.println("Opener not found on stack for " + closerName);
              //System.out.println(" ");
          }
         
          }
          catch (Exception e) {
              e.printStackTrace();
          }
         
        try {
          TagItem tempItem = new TagItem(match.lineNumber, match.startPos, match.endPos+1, match.match);
          ((TagItem)topItem).setMatchingItem(tempItem);
          } catch(Exception e){
          System.err.println("Caught exception: " + e.getMessage());
          e.printStackTrace();
        }
View Full Code Here

    // If it has it means that it is a branch element on the tree, so we pop it onto the stack.
    // If not then it's a child element and so we add it to the child list of the top element
    // of the stack.
     
      tagName = tagName.substring(1, tagName.length());
    TagItem newItem;
    //System.out.println("CFParser::handleCFTag found " + tagName);
   
   
    boolean singleQuoted = false;
    boolean doubleQuoted = false;
    char c;
    for (int i=0;i<tagName.length();i++) {
      c = tagName.charAt(i);
      if (c == '\'' && !doubleQuoted) {
        singleQuoted = !singleQuoted;
      }
      if (c == '\"' && !singleQuoted) {
        doubleQuoted = !doubleQuoted;
      }
      if (c == '<' && !singleQuoted && !doubleQuoted) {
          parserState.addMessage(new ParseError(
              getLineNumber(match.getStartPos()), match.getStartPos(), match.getStartPos() + match.getMatch().length(), match.getMatch(),
              "Invalid token \"" + c + "\" found in opening <b>"  + tagName + "</b> tag. The tag is probably missing a closing \">\""
            ));
         
          throw new FatalException("Fatal parser error. Unable to continue parsing past line " + getLineNumber(match.getStartPos()));
      }
    }
    //    }
       
    //  }
    //}
    //
    // First test to see whether we've found a custom tag. If so we do nothing fancy (yet).
    // Also tests to make sure it catches CFX tags.
    if(tagName.length() >= 3 && (tagName.charAt(2) == '_'
      || (
          (tagName.charAt(2) == 'x' || (tagName.charAt(2) == 'X'))
          && tagName.charAt(3) == '_')
        ))
    {

      newItem = new CfmlCustomTag(getLineNumber(match.startPos), match.startPos, match.endPos, tagName);
      newItem.setItemData(match.match);

    }
    else
    {
      newItem = getNameBasedCfmlTag(tagName, match, getLineNumber(match.startPos));
      newItem.initDictionary(DictionaryManager.getDictionary(DictionaryManager.CFDIC));
      newItem.setItemData(match.match);
    }

    newItem.addAttributes(attrList);
    addTagItemToTree(match, matchStack, isACloser, newItem);
  }
View Full Code Here

    // Util.dumpMatches(matches);
    // System.out.println("=============> Finishing match dump");
    CFDocument newDoc = new CFDocument();
    matchStack = new Stack();
    ArrayList rootElements = new ArrayList();
    TagItem rootItem = new TagItem(0, 0, 0, "Doc Root");
    int matchPos = 0;
    StringBuffer nonParsedTextBuffer = new StringBuffer();
    matchStack.push(rootItem);
    ParseItemMatch lastMatch = null;
    // little hackish way to detect cfscript based cfcs TODO: something better
    if (inData.split("(?i).*component[^>]+\\{").length > 1) {
      parseCFScript(inData);
      newDoc.setDocumentRoot(rootItem);
      return newDoc;
    }
    try {
     
      for(; matchPos < matches.size(); matchPos++)
      {
        ParseItemMatch match = (ParseItemMatch)matches.get(matchPos);
       
        String matchStr = match.match;
        /*
        if(lastMatch != null)
        {
            int difference = match.getStartPos() - lastMatch.getEndPos();
            System.out.println(lastMatch.getMatch() + " -> " + match.getMatch() + ": diff of : "+ difference);
            String nonParsedText = this.data2Parse.substring(lastMatch.getEndPos()+1, difference + lastMatch.getEndPos());
            System.out.println("-> Thinks this is non matched: \'" + nonParsedText + "\'");
            TextNode textNode = new TextNode(match.getLineNumber(), match.getStartPos(), match.getEndPos(), "#TEXT");
            textNode.setNodeText(nonParsedText);
            addDocItemToTree(match, matchStack, textNode);
        }
        */
        lastMatch = match;
       
        if(matchStr.charAt(0) == '<'// Funnily enough this should always be the case!
        {
          if(matchStr.charAt(1) == '/') {
            if(!handleClosingTag(match, matchStack)) {               
              parserState.addMessage(new ParseError(
                  getLineNumber(matchPos), matchPos, matchPos, "",
                  "Something in here is (probably) missing a closing tag or a closing \">\" and thus totally borking the parse!"
                ));
              break;
            }
          } else {
            // get just tag name, e.g. : <cffunction name="blah" becomes cffunction
            String tagName = matchStr.split("[\\s/>]")[0];
            tagName = "<"+tagName.substring(1, tagName.length()).toLowerCase();
            int tagEnd = matchStr.indexOf(tagName)+tagName.length();
            boolean isACloser = false;
            //
            // Find the end of the tag
            int currPos = 0;
            for(int quoteCount = 0; currPos < match.match.length(); currPos++) {
              char currChar = match.match.charAt(currPos);
              boolean inQuotes = (1 == quoteCount % 2);
              if(!inQuotes && currChar == '>') {
                break;
              }
              else if(currChar == '\"')
                quoteCount++;
            }

            //
            // Handle a self-closer (i.e. <cfproperty ... />
            String attributes = "";           
            if(match.match.charAt(currPos-1) == '/') {
              isACloser = true;
              if(match.match.length() - tagEnd >= 2)
                attributes = match.match.substring(tagEnd, match.match.length()-2); // minus one to strip the closing '/>'
            }
            else
              attributes = match.match.substring(tagEnd, match.match.length()-1); // minus one to strip the closing '>'

            switch(match.getMatchType())
            {
              case MATCHER_CFMLTAG:
                if(tagName.startsWith("<cfif") || tagName.startsWith("<cfelseif") || tagName.startsWith("<cfmodule")
                    || tagName.startsWith("<cfset"))               
                {
                  handleCFTag(tagName, match, matchStack, new ArrayList(), isACloser);
                } else {
                  handleCFTag(tagName, match, matchStack, stripAttributes(attributes, match.lineNumber, tagEnd, match), isACloser);                 
                }
                if((tagName.startsWith("<cfif") || tagName.startsWith("<cfelseif") || tagName.startsWith("<cfmodule")
                    || tagName.startsWith("<cfset"))
                    && attributes.trim().length() == 0)
                {
                    userMessage(0,
                        "stripAttributes", tagName + "> requires at least one attribute",
                        USRMSG_ERROR, match);     
                }

                break;
              case MATCHER_CFMLCOMMENT:
                //System.out.println("CFParser::createDocTree() - Got a CFML comment!");
                DocItem newComment = new CfmlComment(
                    match.getLineNumber(),
                    match.getStartPos(),
                    match.getEndPos(),
                    match.getMatch()
                );
               
                newComment.setItemData(match.getMatch());
              addDocItemToTree(match, newComment);
               
                break;
              case MATCHER_CFSCRIPT:
                tagName = tagName.substring(1, tagName.length());
                TagItem newItem;               
                newItem = getNameBasedCfmlTag(tagName.substring(0, "cfscript".length()), match, getLineNumber(match.startPos));
                newItem.initDictionary(DictionaryManager.getDictionary(DictionaryManager.CFDIC));
                newItem.setItemData("");
                addTagItemToTree(match, matchStack, isACloser, newItem);
                handleCFScriptBlock(match, matchStack);
                break;
              default:
                break;
View Full Code Here

  private void handleUnclosedTags(Stack matchStack, DocItem defaultParent) {
    try {
      // If we've got more than one item left on the stack check if any of the remaining items are unclosed custom tags
      if (matchStack.size() > 1) {
        for (int i=0;i<matchStack.size();i++) {
          TagItem t = (TagItem)matchStack.peek();
          String tagName = t.getName();
          //System.out.println("Looking at " + tagName);
          // Look for tags that got left over.
          if (tagName.toLowerCase().startsWith("cf") ) {
            // Mark them as being self closers.
            if (tagName.toLowerCase().startsWith("cf_") || tagName.toLowerCase().startsWith("cfx_")) {
              ((CfmlCustomTag)t).hasCloser= false;
            }
            // Get the current parent of the tag.
            DocItem parent = t.getParent();
            if (parent == null) {
              parent = defaultParent;
            }
            // Don't make the thing a child of itself.
            if (!parent.equals(t)) {
              parent.addChild(t);
 
              CFNodeList childNodes = t.getChildNodes();
              Iterator iter = childNodes.iterator();
              ArrayList deletedChildren = new ArrayList();
              while (iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof DocItem) {
                  DocItem d = (DocItem)o;
                  d.setParent(parent);
                  parent.addChild(d);
                  deletedChildren.add(d);
                  System.out.println("Added " + d.getClass().getName() + " as child of " + parent.getName() + ". Was child of " + tagName);
                }
              }
              iter = deletedChildren.iterator();
              while(iter.hasNext()) {
                t.removeChild((DocItem)iter.next());
              }
            }
          }
        }
       
      }
      // any tags left will be unclosed tags that should be closed
      // or maybe a hybrid (cfmodule poped up without the check)
      while(matchStack.size() > 1) //leave the doc root
      {       
        TagItem orphanTag = (TagItem)matchStack.pop();
        if (!orphanTag.isHybrid()) {         
          parserState.addMessage(new ParseError(
              orphanTag.getLineNumber(), orphanTag.getStartPosition(), orphanTag.getEndPosition(), orphanTag.getName(),
              orphanTag.getName() + " is missing a closing tag"
          ));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

    CFNodeList nodes = docroot.selectNodes("//cfproperty");
    
    Iterator nodeIter = nodes.iterator();
   
    while(nodeIter.hasNext()){
      TagItem property = (TagItem)nodeIter.next();
      StringBuffer sb = new StringBuffer();
     
      String propName = property.getAttributeValue("name");
      String propType = property.getAttributeValue("type");
     
      sb.append("<cffunction name=\"" + createFunctionName("get", propName) + "\" returntype=\"" + propType + "\">\n");
      sb.append("\t<cfreturn "  + propName + " />\n");
      sb.append("</cffunction>");
      sb.append("\n\n");
View Full Code Here

TOP

Related Classes of org.cfeclipse.cfml.parser.docitems.TagItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.