/** * Recursively evaluates an element. * * @param element the element * @return the result of processing the element * @throws ProcessorException if there is an error in processing */ @SuppressWarnings("unchecked") public String evaluate(Element element) throws ProcessorException { // Is it a valid element? if (element == null) { return ""; } // Search for the tag in the processor registry. Class<? extends P> processorClass = null; String elementNamespaceURI = element.getNamespaceURI(); Document elementDocument = element.getDocument(); boolean emitXMLNS = elementDocument != null && (element.equals(element.getDocument().getRootElement()) || (elementNamespaceURI != null && !elementNamespaceURI.equals( element.getDocument().getRootElement().getNamespaceURI()))); if (elementNamespaceURI == null || this._registry.getNamespaceURI().equals(elementNamespaceURI)) { processorClass = this._registry.get(element.getName()); // Process the element with a new instance of the processor. return Classes.getNewInstance(processorClass, "Processor", this._core).process(element, this); } // otherwise (if this element is from a different namespace) if (element.getContent().size() == 0) { return JDOM.renderEmptyElement(element, emitXMLNS); } // otherwise... return JDOM.renderStartTag(element, emitXMLNS) + evaluate(element.getContent()) + JDOM.renderEndTag(element); }
/** * merges content from xmlDocument2 into xmlDocument1 (xmlDocument2 will overwrite nodes from * xmlDocument1) * * @param xmlDocument1 * @param xmlDocument2 * @return */ public static Document mergeXmlDocuments(Document xmlDocument1, Document xmlDocument2) { if (xmlDocument1 == null) { return xmlDocument2; } else if (xmlDocument2 == null) { return xmlDocument1; } Element root1 = xmlDocument1.getRootElement(); Element root2 = xmlDocument2.getRootElement(); if (!root1.getName().equals(root2.getName())) { // we can't merge files with different root nodes return xmlDocument1; } // List<Element> children = root2.getChildren(); List<Element> children = new ArrayList(root2.getChildren()); if (children.size() > 0) { for (Element child : children) { // Element childCopy = (Element) child.clone(); mergeXmlElement(child, root1, true); } } return root1.getDocument(); // return new Document(root1); // we need to detach root1 first if we want to return a new // Document }
/** * 持久化xml文件 * * @param rootElement */ private void saveXML(Element rootElement) { Document doc = rootElement.getDocument(); // 修改服务器端文件 outPutDocToFile(doc, ProjectDutyPathUtil.getServerDutyPath()); // 修改工程中的文件 outPutDocToFile(doc, ProjectDutyPathUtil.getClientDutyPath()); }
Object getDocument(Object node) { if (node instanceof Element) { return ((Element) node).getDocument(); } else if (node instanceof Attribute) { Element parent = ((Attribute) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Text) { Element parent = ((Text) node).getParent(); return parent == null ? null : parent.getDocument(); } else if (node instanceof Document) return node; else if (node instanceof ProcessingInstruction) { return ((ProcessingInstruction) node).getDocument(); } else if (node instanceof EntityRef) { return ((EntityRef) node).getDocument(); } else if (node instanceof Comment) { return ((Comment) node).getDocument(); } return null; }
public ItTreeNode buildProblemNode(Element problem, ItTreeNode treeProject) { ItTreeNode treeProblem = new ItTreeNode(problem.getChildText("name"), problem, null, null); treeProblem.setIcon(new ImageIcon("resources/images/planningProblem.png")); treeModel.insertNodeInto(treeProblem, treeProject, treeProject.getChildCount()); // Build each Object Diagram under the Problem Node Iterator objectDiagrams = problem.getChild("objectDiagrams").getChildren("objectDiagram").iterator(); while (objectDiagrams.hasNext()) { Element objectDiagram = (Element) objectDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode( objectDiagram.getChildText("name") + " - " + objectDiagram.getChildText("sequenceReference"), objectDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/objectDiagram.png")); treeProblem.add(treeDiagram); Iterator objects = objectDiagram.getChild("objects").getChildren("object").iterator(); while (objects.hasNext()) { Element objectReference = (Element) objects.next(); Element object = getElement( problem.getParentElement().getParentElement(), "objects", objectReference.getAttributeValue("id")); if (object != null) { Element itsClass = null; try { XPath path = new JDOMXPath( "project/elements/classes/class[@id=" + object.getChildText("class") + "]"); itsClass = (Element) path.selectSingleNode(problem.getDocument()); } catch (JaxenException e2) { e2.printStackTrace(); } // Element itsClass = getElement(xmlProject, "classes", object.getChildText("class")); ItTreeNode treeObject = new ItTreeNode(object.getChildText("name"), object, objectReference, itsClass); treeObject.setIcon(new ImageIcon("resources/images/object.png")); treeDiagram.add(treeObject); } } } return treeProblem; }
/** * * @param 普通版list 参数列表 */ public void writeptParaList(ArrayList list) { try { String sCaseName=""; String sItem=""; String sCycName=""; HashMap map=null; Document doc = builder.build(xmlFileName); Element root = doc.getRootElement(); Element element = root; Element cycNode=null; map=(HashMap)list.get(0); //参数文件map sItem="Description"; sCaseName=(String)map.get(sItem); mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "Description=" + sCaseName ); sItem="CysName"; sCycName=(String)map.get(sItem); map=(HashMap)list.get(1); //public 参数map cycNode=writeptPublicNode(element,map,sCycName); if( writeCycNode(cycNode,list)==false) //循环 参数 System.err.println(" write cyc node fail"); XMLOutputter outputter = new XMLOutputter("", false, "GB2312"); PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(xmlFileName))); Document myDocument = root.getDocument(); outputter.output(myDocument, out); out.close(); } catch (JDOMException jdome) { jdome.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
/** * Gets the DTD declared in the doctype of the element's owning document. * * @param element The element for which the DTD will be retrieved * @return The DTD declared in the doctype of the element's owning document * @throws DocumentException If an error occurred during DTD retrieval */ public DTD getDTD(Element element) throws DocumentException { if (element.getDocument().getDocType() != null) { String systemId = element.getDocument().getDocType().getSystemID(); DTD dtd = s_dtdMap.get(systemId); // if not in cache, create the DTD and put it in cache if (dtd == null) { Reader reader; URL url; // lookup URL of DTD try { url = new URL(systemId); reader = new InputStreamReader(url.openStream()); } catch (MalformedURLException e) { throw new DocumentException(element.getDocument(), e); } catch (IOException ioe) { throw new DocumentException(element.getDocument(), ioe); } try { dtd = new DTDParser(reader).parse(); } catch (IOException ioe) { throw new DocumentException(element.getDocument(), ioe); } s_dtdMap.put(systemId, dtd); } return dtd; } else { throw new DocumentException( element.getDocument(), "No DTD specified in document " + element.getDocument()); } }
//改写XML文件的某一元素的值 //strRoute为XML文件从根元素开始到该元素的父元素的路径 //strElement为需要读取的元素 //flag为当XML含有多个同名元素时,需要改写元素所处的序号 public void write(String strRoute, String strElement, String strSet, int flag) { //SAXBuilder builder=new SAXBuilder(); try { String str = null; Document doc = builder.build(xmlFileName); Element root = doc.getRootElement(); Element element = root; StringTokenizer st = new StringTokenizer(strRoute, ":"); str = st.nextToken(); while (st.hasMoreTokens()) { str = st.nextToken(); //mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,str); element = element.getChild(str); } // mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"test :"+str); element = (Element) element.getParent(); //若需要改写的不是XML文件的第一个同名元素,则获取该元素 //方法为:将之前的元素依次移到后面,需要改写的元素前移至第一个 /* * if(flag>1) { int j=flag; while(j!=1) { * * Element tmp=element.getChild(str); * element.addContent(tmp.detach()); j--; } } */ element = element.getChild(str).getChild(strElement); // mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"gettxt // "+element.getText()); element.setText(strSet); //若需要改写的不是XML文件的第一个同名元素 //上面改变了次序,需要在成功改写后恢复原有次序 /* * if(flag!=1) { * * java.util.List children=element.getChildren(); Iterator * iterator=children.iterator(); int count=0; * while(iterator.hasNext()) { Element * child=(Element)iterator.next(); count++; } * * System.out.println("count"+count); * * k=(count+1-flag)%count; * * while(k!=0) { Element tmp=element.getChild(str); * element.addContent(tmp.detach()); k--; } } * */ XMLOutputter outputter = new XMLOutputter("", false, "GB2312"); PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(xmlFileName))); Document myDocument = root.getDocument(); outputter.output(myDocument, out); out.close(); } catch (JDOMException jdome) { jdome.printStackTrace(); // mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, xmlFileName // + " is not well-formed\n"); } catch (IOException ioe) { ioe.printStackTrace(); // mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, ioe); } catch (Exception e) { e.printStackTrace(); // mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, // "write not succeed\n"); } }
/** * Creates a new instance with the given Element as target for marshalling. * * @param currentElement must not be null */ public JDOMWriter(String[] namespaces, Element currentElement) { this(namespaces, currentElement.getDocument()); this.currentElement = currentElement; }
public void buildDiagramNode(Element xmlProject, ItTreeNode treeProject) { Iterator diagramsIterator = xmlProject.getChild("diagrams").getChildren().iterator(); while (diagramsIterator.hasNext()) { Element diagrams = (Element) diagramsIterator.next(); // chevere KaosDiagram if (diagrams.getName().equals("KaosDiagrams")) { Element kaosDiagram = diagrams.getChild("name"); Element goalDiagram = diagrams.getChild("GoalDiagram"); Element operDiagram = diagrams.getChild("OperDiagram"); Element objectDiagram = diagrams.getChild("ObjectDiagram"); Element agentDiagram = diagrams.getChild("AgentDiagram"); ItTreeNode treeKAOS = new ItTreeNode(kaosDiagram.getText(), kaosDiagram, null, null); ItTreeNode treeGoal = new ItTreeNode(goalDiagram.getChild("name").getText(), goalDiagram, null, null); // treeGoal.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeGoal.setIcon(new ImageIcon("resources/images/goal_icono.png")); // Insering all goals expectation for a goal diagram Iterator list_goals_expectation = goalDiagram .getChild("goalsExpe") .getChildren("goal") .iterator(); // (Element)goalDiagram.getChildren("goals"); while (list_goals_expectation.hasNext()) { Element goal = (Element) list_goals_expectation.next(); ItTreeNode treeDiagram = new ItTreeNode(goal.getChildText("name"), goal, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/expetativa.png")); treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount()); } // Insering all goals expectation for a goal diagram Iterator list_goals_requi = goalDiagram .getChild("goalsReq") .getChildren("goal") .iterator(); // (Element)goalDiagram.getChildren("goals"); while (list_goals_requi.hasNext()) { Element goal = (Element) list_goals_requi.next(); ItTreeNode treeDiagram = new ItTreeNode(goal.getChildText("name"), goal, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/requirement.png")); treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount()); } // Insering all agents for agoal diagram. Iterator list_agents = goalDiagram .getChild("agents") .getChildren("agent") .iterator(); // (Element)goalDiagram.getChildren("goals"); while (list_agents.hasNext()) { Element agent = (Element) list_agents.next(); ItTreeNode treeDiagram = new ItTreeNode(agent.getChildText("name"), agent, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/agent1.png")); treeModel.insertNodeInto(treeDiagram, treeGoal, treeGoal.getChildCount()); } ItTreeNode treeOp = new ItTreeNode(operDiagram.getChild("name").getText(), operDiagram, null, null); treeOp.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); ItTreeNode treeObj = new ItTreeNode(objectDiagram.getChild("name").getText(), objectDiagram, null, null); treeObj.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); ItTreeNode treeAg = new ItTreeNode(agentDiagram.getChild("name").getText(), agentDiagram, null, null); treeAg.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(treeGoal, treeKAOS, treeKAOS.getChildCount()); treeModel.insertNodeInto(treeOp, treeKAOS, treeKAOS.getChildCount()); treeModel.insertNodeInto(treeObj, treeKAOS, treeKAOS.getChildCount()); treeModel.insertNodeInto(treeAg, treeKAOS, treeKAOS.getChildCount()); treeKAOS.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(treeKAOS, treeProject, treeProject.getChildCount()); /* Element kaosDiagram = diagrams.getChild("name"); ItTreeNode name = new ItTreeNode(kaosDiagram.getText(), kaosDiagram, null, null); Element goalDiagram1 = diagrams.getChild("GoalDiagram"); name.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(name, treeProject, treeProject.getChildCount()); Iterator goalDiagrams = diagrams.getChildren("GoalDiagram").iterator(); while (goalDiagrams.hasNext()){ Element goalDiagram = (Element)goalDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(goalDiagram.getChildText("name"), goalDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator agents = goalDiagram.getChild("agents").getChildren("agent").iterator(); while (agents.hasNext()){ Element actor = (Element) agents.next(); ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null); treeActor.setIcon(new ImageIcon("resources/images/agent1.png")); treeDiagram.add(treeActor); } Iterator useCases = goalDiagram.getChild("goals").getChildren("goal").iterator(); while (useCases.hasNext()){ Element useCase = (Element) useCases.next(); ItTreeNode treeUseCase = new ItTreeNode(useCase.getChildText("name"), useCase, null, null); treeUseCase.setIcon(new ImageIcon("resources/images/goal1.png")); treeDiagram.add(treeUseCase); } }*/ /* Iterator agentDiagram = diagrams.getChildren("AgentDiagram").iterator(); while (goalDiagrams.hasNext()){ Element useCaseDiagram = (Element)goalDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(useCaseDiagram.getChildText("name"), useCaseDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator agents = useCaseDiagram.getChild("agents").getChildren("agent").iterator(); while (agents.hasNext()){ Element actor = (Element) agents.next(); ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null); treeActor.setIcon(new ImageIcon("resources/images/agent1.png")); treeDiagram.add(treeActor); } Iterator useCases = useCaseDiagram.getChild("goals").getChildren("goal").iterator(); while (useCases.hasNext()){ Element useCase = (Element) useCases.next(); ItTreeNode treeUseCase = new ItTreeNode(useCase.getChildText("name"), useCase, null, null); treeUseCase.setIcon(new ImageIcon("resources/images/goal1.png")); treeDiagram.add(treeUseCase); } }*/ } // chevere // Use Case Diagrams if (diagrams.getName().equals("useCaseDiagrams")) { Iterator useCaseDiagrams = diagrams.getChildren("useCaseDiagram").iterator(); while (useCaseDiagrams.hasNext()) { Element useCaseDiagram = (Element) useCaseDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(useCaseDiagram.getChildText("name"), useCaseDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/useCaseDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator actors = useCaseDiagram.getChild("actors").getChildren("actor").iterator(); while (actors.hasNext()) { Element actor = (Element) actors.next(); ItTreeNode treeActor = new ItTreeNode(actor.getChildText("name"), actor, null, null); treeActor.setIcon(new ImageIcon("resources/images/actor.png")); treeDiagram.add(treeActor); } Iterator useCases = useCaseDiagram.getChild("useCases").getChildren("useCase").iterator(); while (useCases.hasNext()) { Element useCase = (Element) useCases.next(); ItTreeNode treeUseCase = new ItTreeNode(useCase.getChildText("name"), useCase, null, null); treeUseCase.setIcon(new ImageIcon("resources/images/useCase.png")); treeDiagram.add(treeUseCase); } } } // Class Diagrams else if (diagrams.getName().equals("classDiagrams")) { Iterator classDiagrams = diagrams.getChildren("classDiagram").iterator(); while (classDiagrams.hasNext()) { Element classDiagram = (Element) classDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(classDiagram.getChildText("name"), classDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/classDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator classes = classDiagram.getChild("classes").getChildren("class").iterator(); while (classes.hasNext()) { Element classReference = (Element) classes.next(); Element Class = getElement(xmlProject, "classes", classReference.getAttributeValue("id")); if (Class != null) { ItTreeNode treeClass = new ItTreeNode(Class.getChildText("name"), Class, classReference, null); treeClass.setIcon(new ImageIcon("resources/images/class.png")); treeDiagram.add(treeClass); Iterator attributes = Class.getChild("attributes").getChildren("attribute").iterator(); for (int i = 0; attributes.hasNext(); i++) { Element attribute = (Element) attributes.next(); ItTreeNode treeAttribute = new ItTreeNode(attribute.getChildText("name"), attribute, null, null); treeAttribute.setIcon(new ImageIcon("resources/images/attribute.png")); treeClass.add(treeAttribute); } Iterator operators = Class.getChild("operators").getChildren("operator").iterator(); while (operators.hasNext()) { Element operator = (Element) operators.next(); ItTreeNode treeOperator = new ItTreeNode(operator.getChildText("name"), operator, null, null); treeOperator.setIcon(new ImageIcon("resources/images/operator.png")); treeClass.add(treeOperator); } } } } } // State Chart Diagrams else if (diagrams.getName().equals("stateMachineDiagrams")) { Iterator stateDiagrams = diagrams.getChildren("stateMachineDiagram").iterator(); while (stateDiagrams.hasNext()) { Element stateDiagram = (Element) stateDiagrams.next(); // Get class Element classReference = null; if (!stateDiagram.getChildText("class").equals("")) { try { XPath path = new JDOMXPath( "project/elements/classes/class[@id=" + stateDiagram.getChildText("class") + "]"); classReference = (Element) path.selectSingleNode(stateDiagram.getDocument()); } catch (JaxenException e2) { e2.printStackTrace(); } } ItTreeNode treeDiagram = new ItTreeNode(stateDiagram.getChildText("name"), stateDiagram, null, classReference); treeDiagram.setIcon(new ImageIcon("resources/images/stateMachineDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator states = stateDiagram.getChild("states").getChildren("state").iterator(); while (states.hasNext()) { Element state = (Element) states.next(); ItTreeNode treeState = new ItTreeNode(state.getChildText("name"), state, null, null); treeState.setIcon(new ImageIcon("resources/images/state.png")); treeDiagram.add(treeState); } } } // Activity Diagrams else if (diagrams.getName().equals("activityDiagrams")) { Iterator activityDiagrams = diagrams.getChildren("activityDiagram").iterator(); while (activityDiagrams.hasNext()) { Element activityDiagram = (Element) activityDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(activityDiagram.getChildText("name"), activityDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/activityDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); } } // Timing Diagrams else if (diagrams.getName().equals("timingDiagrams")) { Iterator timingDiagrams = diagrams.getChildren("timingDiagram").iterator(); while (timingDiagrams.hasNext()) { Element timingDiagram = (Element) timingDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(timingDiagram.getChildText("name"), timingDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/activityDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); } } // Object Diagrams else if (diagrams.getName().equals("objectDiagrams")) { Iterator objectDiagrams = diagrams.getChildren("objectDiagram").iterator(); while (objectDiagrams.hasNext()) { Element objectDiagram = (Element) objectDiagrams.next(); ItTreeNode treeDiagram = new ItTreeNode(objectDiagram.getChildText("name"), objectDiagram, null, null); treeDiagram.setIcon(new ImageIcon("resources/images/objectDiagram.png")); treeModel.insertNodeInto(treeDiagram, treeProject, treeProject.getChildCount()); Iterator objects = objectDiagram.getChild("objects").getChildren("object").iterator(); while (objects.hasNext()) { Element objectReference = (Element) objects.next(); Element object = getElement(xmlProject, "objects", objectReference.getAttributeValue("id")); if (object != null) { Element itsClass = getElement(xmlProject, "classes", object.getChildText("class")); ItTreeNode treeObject = new ItTreeNode(object.getChildText("name"), object, objectReference, itsClass); treeObject.setIcon(new ImageIcon("resources/images/object.png")); treeDiagram.add(treeObject); } } } } // Planning domains else if (diagrams.getName().equals("planningDomains")) { Iterator domains = diagrams.getChildren("domain").iterator(); while (domains.hasNext()) { Element domain = (Element) domains.next(); buildDomainNode(domain, treeProject); } } // Planning Problems /*else if (diagrams.getName().equals("planningProblems")){ Iterator problems = diagrams.getChildren("problem").iterator(); while(problems.hasNext()){ Element problem = (Element)problems.next(); buildProblemNode(problem, treeProject); } }*/ } }
public void buildPDDLNode(Element xmlProject, ItTreeNode treeProject, String path) { // domain files Iterator domainsIterator = xmlProject.getChild("pddldomains").getChildren().iterator(); while (domainsIterator.hasNext()) { Element pddldomain = (Element) domainsIterator.next(); ItTreeNode treePDDL = new ItTreeNode(pddldomain.getChildText("name"), pddldomain, null, null); treePDDL.setIcon(new ImageIcon("resources/images/domain.png")); treeModel.insertNodeInto(treePDDL, treeProject, treeProject.getChildCount()); } // Problem Instance files Element problemInstancesRoot = xmlProject.getChild("problemInstances"); ItTreeNode treeProblemInstPDDL = new ItTreeNode("Problem Instances", problemInstancesRoot, null, null); treeProblemInstPDDL.setIcon(new ImageIcon("resources/images/openreport.png")); treeModel.insertNodeInto(treeProblemInstPDDL, treeProject, treeProject.getChildCount()); File theproject = new File(path); // File folder = new File(theproject.getParent()); File folder = theproject.getParentFile(); FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { if (name != null && name.toLowerCase().endsWith(".pddl")) { return true; } else { return false; } } }; // PDDLFileFilter ff = new PDDLFileFilter(); File[] listOfFiles = folder.listFiles(filter); // sorting the files (alphabetical order) Arrays.sort( listOfFiles, new Comparator<File>() { public int compare(File a, File b) { return a.getName().compareTo(b.getName()); } }); for (int i = 0; i < listOfFiles.length; i++) { File eachfile = listOfFiles[i]; // System.out.println("File " + eachfile.getName()); String filename = eachfile.getName(); // check if file is a domain file Element pddldomainNode = null; try { XPath dpath = new JDOMXPath("pddlproject/pddldomains/pddldomain[name='" + filename + "']"); pddldomainNode = (Element) dpath.selectSingleNode(xmlProject.getDocument()); } catch (JaxenException e1) { e1.printStackTrace(); } if (pddldomainNode == null) { Element problemInstance = new Element("pddlproblem"); // problemInstance.setText(filename); problemInstance.setAttribute("filename", filename); problemInstance.setAttribute("file", eachfile.getAbsolutePath()); Element thename = new Element("name"); thename.setText(filename); problemInstance.addContent(thename); problemInstancesRoot.addContent(problemInstance); ItTreeNode nodeProblemInstPDDL = new ItTreeNode(filename, problemInstance, null, null); nodeProblemInstPDDL.setIcon(new ImageIcon("resources/images/problem.png")); treeModel.insertNodeInto( nodeProblemInstPDDL, treeProblemInstPDDL, treeProblemInstPDDL.getChildCount()); } } }
protected boolean writeXML(){ return XMLHandler.writeXML(filename,root.getDocument()); }