示例#1
1
 /**
  * Factory method, equivalent to a "fromXML" for step creation. Looks for a class with the same
  * name as the XML tag, with the first letter capitalized. For example, <call /> is
  * abbot.script.Call.
  */
 public static Step createStep(Resolver resolver, Element el) throws InvalidScriptException {
   String tag = el.getName();
   Map attributes = createAttributeMap(el);
   String name = tag.substring(0, 1).toUpperCase() + tag.substring(1);
   if (tag.equals(TAG_WAIT)) {
     attributes.put(TAG_WAIT, "true");
     name = "Assert";
   }
   try {
     name = "abbot.script." + name;
     Log.debug("Instantiating " + name);
     Class cls = Class.forName(name);
     try {
       // Steps with contents require access to the XML element
       Class[] argTypes = new Class[] {Resolver.class, Element.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, el, attributes});
     } catch (NoSuchMethodException nsm) {
       // All steps must support this ctor
       Class[] argTypes = new Class[] {Resolver.class, Map.class};
       Constructor ctor = cls.getConstructor(argTypes);
       return (Step) ctor.newInstance(new Object[] {resolver, attributes});
     }
   } catch (ClassNotFoundException cnf) {
     String msg = Strings.get("step.unknown_tag", new Object[] {tag});
     throw new InvalidScriptException(msg);
   } catch (InvocationTargetException ite) {
     Log.warn(ite);
     throw new InvalidScriptException(ite.getTargetException().getMessage());
   } catch (Exception exc) {
     Log.warn(exc);
     throw new InvalidScriptException(exc.getMessage());
   }
 }
示例#2
0
	/**
	 *  普通版填写包的公共部分
	 * @param root	开始节点
	 * @param map	参数map
	 * @param sCycName	循环节点名
	 * @return
	 */
	public Element writeptPublicNode(Element root,HashMap map,String sCycName)
	{
		Element node=null;
		try
		{
			String sName="";
			String sValue="";
			List list=root.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				sValue=(String)map.get(sName);
				//System.err.println("sName:"+sName+":"+sValue);
				if(sCycName.equals(sName)&&(root.getName()).trim().equals("ReqParamSet"))
				{
					//System.err.println("find cyc node:"+sName );
					return node;
				}
				else if(sValue!=null && !"".equals(sValue) )
					node.setText(sValue);
				node=writeptPublicNode(node,map,sCycName);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return node;
	}
示例#3
0
	/*
	 * 递归完成查找
	 * para: Element root 开始查找节点
	 */
	public Element findNode(Element root,String sNodeName)
	{
		Element node =null;
		try
		{
			String sName="";
			List list=root.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				//System.err.println("node name:"+sName+"-"+sNodeName);
				if(sName.equals(sNodeName))
				{
					System.err.println("find the node:"+sName);
					return node;
				}
				node=findNode(node,sNodeName);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return node;
	}
 private void writeContent(final int end, final List childElements, final int depth)
     throws IOException {
   // sets index to end
   for (final Iterator i = childElements.iterator(); i.hasNext(); ) {
     final Element element = (Element) i.next();
     final int elementBegin = element.begin;
     if (elementBegin >= end) break;
     if (indentAllElements) {
       writeText(elementBegin, depth);
       writeElement(element, depth, end, false, false);
     } else {
       if (inlinable(element)) continue; // skip over elements that can be inlined.
       writeText(elementBegin, depth);
       final String elementName = element.getName();
       if (elementName == HTMLElementName.PRE || elementName == HTMLElementName.TEXTAREA) {
         writeElement(element, depth, end, true, true);
       } else if (elementName == HTMLElementName.SCRIPT) {
         writeElement(element, depth, end, true, false);
       } else {
         writeElement(
             element,
             depth,
             end,
             false,
             !removeLineBreaks && containsOnlyInlineLevelChildElements(element));
       }
     }
   }
   writeText(end, depth);
 }
示例#5
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
示例#6
0
 public void handleElement(Element e) {
   // create family
   if (e.getName().equals("family")) {
     try {
       lexicon.add(new Family(e));
     } catch (RuntimeException exc) {
       System.err.println("Skipping family: " + e.getAttributeValue("name"));
       System.err.println(exc.toString());
     }
   }
   // save distributive attributes
   else if (e.getName().equals("distributive-features")) distrElt = e;
   // save licensing features
   else if (e.getName().equals("licensing-features")) licensingElt = e;
   // save relation sort order
   else if (e.getName().equals("relation-sorting")) relationSortingElt = e;
 }
示例#7
0
  public void compileParser(Trace trace, Strictness strictness) {

    SGrammar sGrammar = new SGrammar(this);
    OldGrammar oldGrammar = null;
    for (Production production : sGrammar.getProductions()) {

      if (oldGrammar == null) {
        oldGrammar = new OldGrammar(this, production.getName(), production);
      }

      OldProduction oldProduction = oldGrammar.getProduction(production.getName(), production);

      for (Alternative alternative : production.getAlternatives()) {

        OldAlternative oldAlternative = oldProduction.addAlternative("", alternative);

        for (Element element : alternative.getElements()) {
          OldElement oldElement;
          if (element instanceof Element.TokenElement) {
            Element.TokenElement tokenElement = (Element.TokenElement) element;
            oldElement =
                oldAlternative.addTokenElement(
                    this,
                    element.getName(),
                    oldGrammar.getToken(tokenElement.getTypeName()),
                    tokenElement);
          } else {
            Element.ProductionElement productionElement = (Element.ProductionElement) element;
            oldElement =
                oldAlternative.addProductionElement(
                    element.getName(),
                    oldGrammar.getProduction(
                        element.getTypeName(), productionElement.getReference()),
                    productionElement);
          }
          sGrammar.addOldElement(element, oldElement);
        }
      }
    }

    oldGrammar.stabilize();
    oldGrammar.computeShortestLengthAndDetectUselessProductions();
    sGrammar.setLRAutomaton(new LRAutomaton(oldGrammar, trace));
    this.simplifiedGrammar = sGrammar;
  }
示例#8
0
  private void load_snap_from_xml(Element snap, StructureCollection structs, LinkedList tempList)
      throws VisualizerLoadException {
    Iterator iterator = snap.getChildren().iterator();

    if (!iterator.hasNext()) throw new VisualizerLoadException("Ran out of elements");

    structs.loadTitle((Element) (iterator.next()), tempList, this);
    structs.calcDimsAndStartPts(tempList, this);

    if (!iterator.hasNext()) return;
    Element child = (Element) iterator.next();

    if (child.getName().compareTo("doc_url") == 0) {
      // load the doc_url
      add_a_documentation_URL(child.getText().trim());
      if (!iterator.hasNext()) return;
      child = (Element) iterator.next();
    }

    if (child.getName().compareTo("pseudocode_url") == 0) {
      // load the psuedocode_url
      add_a_pseudocode_URL(child.getText().trim());
      if (!iterator.hasNext()) return;
      child = (Element) iterator.next();
    }

    if (child.getName().compareTo("audio_text") == 0) {
      // load the psuedocode_url
      add_audio_text(child.getText().trim());
      if (!iterator.hasNext()) return;
      child = (Element) iterator.next();
    }

    // create & load the individual structures, hooking them into the StructureCollection.
    // linespernode : calculate it at end of loadStructure call
    while (child.getName().compareTo("question_ref") != 0) {
      StructureType child_struct = assignStructureType(child);
      child_struct.loadStructure(child, tempList, this);
      structs.addChild(child_struct);

      if (!iterator.hasNext()) return;
      child = (Element) iterator.next();
    }

    if (child.getName().compareTo("question_ref") == 0) {
      // set up question ref
      add_a_question_xml(child.getAttributeValue("ref"));
    } else
      // should never happen
      throw new VisualizerLoadException(
          "Expected question_ref element, but found " + child.getName());

    if (iterator.hasNext()) {
      child = (Element) iterator.next();
      throw new VisualizerLoadException(
          "Found " + child.getName() + " when expecting end of snap.");
    }
  } // load_snap_from_xml
示例#9
0
 public void handleElement(Element e) {
   // create morph item
   if (e.getName().equals("entry")) {
     try {
       morphItems.add(new MorphItem(e));
     } catch (RuntimeException exc) {
       System.err.println("Skipping morph item: " + e.getAttributeValue("word"));
       System.err.println(exc.toString());
     }
   }
   // create macro item
   else if (e.getName().equals("macro")) {
     try {
       macroItems.add(new MacroItem(e));
     } catch (RuntimeException exc) {
       System.err.println("Skipping macro item: " + e.getAttributeValue("name"));
       System.err.println(exc.toString());
     }
   }
 }
示例#10
0
  /**
   * This will invoke the <code>endElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   */
  private void endElement(Element element) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    try {
      contentHandler.endElement(namespaceURI, localName, rawName);
    } catch (SAXException se) {
      throw new JDOMException("Exception in endElement", se);
    }
  }
示例#11
0
	/**
	 *  新增循环节点
	 * @param cycNode 循环节点
	 * @return
	 */
	public Element addCycNode(Element cycNode)
	{
		Element node=cycNode;
		Element child=null;
		Element newNode=null;
		Element tmpNode=null;
		String sName="";
		if(cycNode==null)
			return newNode;
		newNode=new Element(node.getName());
		node.getParent().addContent(newNode);
		List cList=node.getChildren();
		for(int i=0;i<cList.size();i++)
		{
			child=(Element)cList.get(i);
			sName=child.getName();
			sName=sName.trim();
			tmpNode=new Element(sName);
			newNode.addContent(tmpNode);
		}
		return newNode;
	}
 private boolean containsOnlyInlineLevelChildElements(final Element element) {
   // returns true if the element contains only inline-level elements except for SCRIPT elements.
   final Collection childElements = element.getChildElements();
   if (childElements.isEmpty()) return true;
   for (final Iterator i = childElements.iterator(); i.hasNext(); ) {
     final Element childElement = (Element) i.next();
     final String elementName = childElement.getName();
     if (elementName == HTMLElementName.SCRIPT
         || !HTMLElements.getInlineLevelElementNames().contains(elementName)) return false;
     if (!containsOnlyInlineLevelChildElements(childElement)) return false;
   }
   return true;
 }
示例#13
0
  /** Make a keybinding out of an XML element */
  public static KeyBinding readXML(Element e) {
    try {
      String plugin = e.getAttributeValue("plugin");
      String desc = e.getAttributeValue("desc");
      KeyBinding b = new KeyBinding(plugin, desc, null);

      for (Object neo : e.getChildren()) {
        Element ne = (Element) neo;
        if (ne.getName().equals("char"))
          b.types.add(new TypeChar(ne.getAttributeValue("char").charAt(0)));
        else if (ne.getName().equals("keycode"))
          b.types.add(
              new TypeKeycode(
                  ne.getAttribute("keyCode").getIntValue(),
                  ne.getAttribute("modifier").getIntValue()));
        else if (ne.getName().equals("jinput"))
          b.types.add(
              new TypeJInput(
                  ne.getAttributeValue("ident"), ne.getAttribute("value").getFloatValue()));
      }

      // backwards compatibility
      if (e.getAttribute("key") != null) {
        TypeChar kb = new TypeChar(e.getAttributeValue("key").charAt(0));
        b.types.add(kb);
      } else if (e.getAttribute("keyCode") != null) {
        TypeKeycode kb =
            new TypeKeycode(
                e.getAttribute("keyCode").getIntValue(), e.getAttribute("modifier").getIntValue());
        b.types.add(kb);
      }
      return b;
    } catch (DataConversionException e1) {
      e1.printStackTrace();
      return null;
    }
  }
 private boolean inlinable(final Element element) {
   // returns true if the specified element should be inlined
   final StartTagType startTagType = element.getStartTag().getStartTagType();
   if (startTagType == StartTagType.DOCTYPE_DECLARATION) return false;
   if (startTagType != StartTagType.NORMAL) return true;
   // element is a normal type
   final String elementName = element.getName();
   if (elementName == HTMLElementName.SCRIPT) return !indentScriptElements;
   if (removeLineBreaks && !HTMLElements.getElementNames().contains(elementName))
     return true; // inline non-HTML elements if removing line breaks
   if (!HTMLElements.getInlineLevelElementNames().contains(elementName)) return false;
   // element is inline type
   if (removeLineBreaks) return true;
   return containsOnlyInlineLevelChildElements(
       element); // only inline if it doesn't illegally contain non-inline elements
 }
示例#15
0
	/** 
	 * 
	 * @param map	需要写入的参数map
	 * @param start 开始节点
	 * @param bNew  是否新增节点再写入参数
	 * @return
	 */
	public void writeParaMap(Element start,HashMap map)
	{
		try
		{
			String sName="";
			String sValue="";
			Element node=null;
			List list=start.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				sValue=(String)map.get(sName);
				if(sValue!=null && !"".equals(sValue) );
					node.setText(sValue);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return ;
	}
示例#16
0
 private StructureType assignStructureType(Element structure) throws VisualizerLoadException {
   String name = structure.getName().toLowerCase();
   if (name.compareTo("graph") == 0) {
     if (structure.getAttributeValue("weighted").compareTo("true") == 0)
       return new Graph_Network("NETWORK");
     else return new Graph_Network("GRAPH");
   } else if (name.equals("array")) return new MD_Array();
   else if (name.equals("no3darray")) return new No3darray();
   else if (name.equals("linkedlist")) return new VisLinkedList();
   else if (name.equals("no3dlinkedlist")) return new No3dLinkedList();
   else if (name.equals("linkedlistnonull")) return new VisLinkedListNoNull();
   else if (name.equals("bargraph")) return new BarScat("BAR");
   else if (name.equals("scattergraph"))
     return new BarScat(
         "SCAT"); // not implemented in xml dtd, and does not have a load-from-xml method defined
   else if (name.equals("stack")) return new Stack();
   else if (name.equals("queue")) return new Queue();
   else if (name.equals("tree")) {
     if (structure.getChild("binary_node") != null) return new BinaryTree();
     else return new GeneralTree();
   } else if (name.equals("text")) return new TextStructure();
   // if the XML element name is different from your structure's name, you can do something like
   // this:
   // 	else if( name.equalsIgnoreCase("node"))
   // 	    return new Node();
   else if (name.equals("legend")) return new LegendofColors();
   else {
     // try dynamic typing
     try {
       return assignStructureType(name);
     } catch (Exception e) {
       throw new VisualizerLoadException(
           "Unable to instantiate class \"" + name + "\":\n" + e.getMessage());
     }
   }
 }