List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
public void saveGroup(Group inGroup) throws UserManagerException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("group"); if (inGroup.getId() == null) { int id = getUserIdCounter().incrementCount(); String inAccount = String.valueOf(id); inGroup.setId(inAccount);/*from ww w. j av a 2 s . co m*/ } root.addAttribute("id", inGroup.getId()); Element groupNameElem = root.addElement("group-name"); groupNameElem.setText(inGroup.getName()); Element permissionsElem = root.addElement("permissions"); for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) { Object permission = (Object) iter.next(); Element permissionElem = permissionsElem.addElement("permission"); permissionElem.setText(permission.toString()); } MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); root.add(propertiesElem); } File file = loadGroupFile(inGroup.getId()); getXmlUtil().saveXml(doc, file); getGroupIdToGroupMap().put(inGroup.getId(), inGroup); }
From source file:com.openedit.users.filesystem.MapPropertyContainer.java
License:Open Source License
protected Element createPropertiesElement(String inElementName) { Element propertiesElem = DocumentFactory.getInstance().createElement(inElementName); for (Iterator iter = getRealProperties().entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); if (entry.getValue() != null) { Element propertyElem = propertiesElem.addElement("property"); propertyElem.addAttribute("name", entry.getKey().toString()); propertyElem.addAttribute("value", entry.getValue().toString()); }/*from www . j av a 2 s .co m*/ } return propertiesElem; }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
public void saveUser(User user) throws UserManagerException { if (user.isVirtual()) { log.error("Cannot save virtual users: " + user.getUserName()); return;// w w w . j a v a 2 s . c o m } DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); Element userElem = doc.addElement("user"); userElem.addAttribute("enabled", Boolean.toString(user.isEnabled())); if (user.getUserName() == null) { int id = getUserIdCounter().incrementCount(); String newid = String.valueOf(id); user.setId(newid); } Element userNameElem = userElem.addElement("user-name"); userNameElem.addCDATA(user.getUserName()); Element passwordElem = userElem.addElement("password"); // if (user.getPassword() != null && !user.getPassword().equals("")) { String ps = user.getPassword(); ps = encrypt(ps); // password may have changed we should set it so it's not in plain // text anymore. user.setPassword(ps); passwordElem.addCDATA(ps); } Element creationDateElem = userElem.addElement("creation-date"); if (user.getCreationDate() != null) { creationDateElem.setText(String.valueOf(user.getCreationDate().getTime())); } else { creationDateElem.setText(String.valueOf(System.currentTimeMillis())); } // Tuan add property lastLogined-Time Element lastLoginTime = userElem.addElement("lastLogined-Time"); lastLoginTime.setText(DateStorageUtil.getStorageUtil().formatForStorage(new Date())); MapPropertyContainer map = (MapPropertyContainer) user.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); userElem.add(propertiesElem); } if (user.getGroups() != null) { for (Iterator iter = user.getGroups().iterator(); iter.hasNext();) { Group group = (Group) iter.next(); Element child = userElem.addElement("group"); child.addAttribute("id", group.getId()); } } synchronized (user) { // File file = loadUserFile(user.getUserName()); XmlFile xfile = new XmlFile(); xfile.setRoot(doc.getRootElement()); xfile.setPath(getUserDirectory() + "/" + user.getUserName() + ".xml"); getXmlArchive().saveXml(xfile, null); getUserNameToUserMap().put(user.getUserName(), user); } }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
public void saveGroup(Group inGroup) throws UserManagerException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("group"); if (inGroup.getId() == null) { int id = getUserIdCounter().incrementCount(); String inAccount = String.valueOf(id); inGroup.setId(inAccount);//from ww w. j ava 2 s . c o m } root.addAttribute("id", inGroup.getId()); Element groupNameElem = root.addElement("group-name"); groupNameElem.setText(inGroup.getName()); Element permissionsElem = root.addElement("permissions"); for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) { Object permission = (Object) iter.next(); Element permissionElem = permissionsElem.addElement("permission"); permissionElem.setText(permission.toString()); } MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); root.add(propertiesElem); } File file = loadGroupFile(inGroup.getId()); getXmlUtil().saveXml(doc, file); getGroupIdToGroupMap().remove(inGroup.getId()); }
From source file:com.orange.atk.atkUI.anaHopper.HopperStep.java
License:Apache License
@Override // public Verdict analyse(StatusBar statusbar,String profileName, // IAnalysisMonitor monitor) public Verdict analyse(IAnalysisMonitor monitor) { try {/*from w w w. j a v a2s .co m*/ check(); init(); } catch (Alert a) { this.outFilePath = null; this.verdict = Verdict.SKIPPED; this.skippedMessage = a.getMessage().trim(); newLastAnalysisResult(new HopperStepAnalysisResult(getFlashFileDigest(), outFilePath, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; } String tempDir = Platform.TMP_DIR; XMLOutput jatkResults = new XMLOutput(tempDir, "jatkresults"); Element flashResultsElem = jatkResults.root(); flashResultsElem.addAttribute("flashfile", jatkFilePath); Calendar cal = new GregorianCalendar(); String currentDate = cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + cal.get(Calendar.YEAR); flashResultsElem.addAttribute("date", currentDate); flashResultsElem.addAttribute("matosversion", Configuration.getVersion()); try { // on lance le test { Thread.sleep(4000); launchtest(); } } catch (Exception e) { Logger.getLogger(this.getClass()) .error("Problem in analysis of the following hopper test: " + jatkFilePath, e); } String outFolder = this.outFilePath + File.separator + "report.html"; jatkResults.generate(); File reportFile = null; if (outFolder != null) { reportFile = new File(outFolder); } outFolder = reportFile.getAbsolutePath(); newLastAnalysisResult(new HopperStepAnalysisResult(getFlashFileDigest(), outFolder, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; }
From source file:com.orange.atk.atkUI.anaHopper.HopperStep.java
License:Apache License
@Override public void save(Element root, int stepNumber) { Element anaElem = root.addElement(TYPE); anaElem.addAttribute("name", "hopperstep_" + stepNumber); anaElem.addAttribute("file", getFlashFilePath()); if (getLogin() != null) { anaElem.addAttribute("login", getLogin()); anaElem.addAttribute("password", getPassword()); }//from w w w.j a va2 s. c o m if (getUseragent() != null) { anaElem.addAttribute("useragent", getUseragent()); } if (getXmlfilepath() != null) { anaElem.addAttribute("configfile", getXmlfilepath()); } Enumeration<String> paramKeys = hopperStepParam.keys(); while (paramKeys.hasMoreElements()) { String key = paramKeys.nextElement(); anaElem.addAttribute(key, hopperStepParam.get(key)); } }
From source file:com.orange.atk.atkUI.anaMixScript.MixScriptStep.java
License:Apache License
@Override //public Verdict analyse(StatusBar statusBar, String profileName, IAnalysisMonitor monitor) public Verdict analyse(IAnalysisMonitor monitor) throws LicenceException { try {// w ww .j a va2 s . com check(); init(); } catch (Alert a) { this.outFilePath = null; this.verdict = Verdict.SKIPPED; this.skippedMessage = a.getMessage().trim(); newLastAnalysisResult(new MixScriptStepAnalysisResult(getFlashFileDigest(), outFilePath, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; } String tempDir = Platform.TMP_DIR; XMLOutput mixScriptResults = new XMLOutput(tempDir, "mixScriptresults"); Element flashResultsElem = mixScriptResults.root(); flashResultsElem.addAttribute("flashfile", mixScriptFilePath); Calendar cal = new GregorianCalendar(); String currentDate = cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + cal.get(Calendar.YEAR); flashResultsElem.addAttribute("date", currentDate); flashResultsElem.addAttribute("matosversion", Configuration.getVersion()); // Verdict verdict = Verdict.PASSED; //anaflash analysis // AnajatkPhase anaflashPhase = new AnajatkPhase(flashFile, // (MixScriptSecurityProfile)profile, flashResultsElem); try { // on lance le test //init // statusBar.setMessage("Check Initialisation"); verdict = launchtest(); //outFilePath = outFilePath + File.separator + "report.html"; } catch (Exception e) { // TODO handle Phone exception Out.log.println("Problem in analysis of the following flash file: " + mixScriptFilePath); e.printStackTrace(); } mixScriptResults.generate(); File reportFile = null; if (outFilePath != null) { reportFile = new File(outFilePath); } else { reportFile = new File(tempDir, "report.html"); } // File flashResultsFile = mixScriptResults.getFile(); // FlashReportGenerator reportGenerator = new FlashReportGenerator(profile // .getSecurityProfileParser(), flashResultsFile, reportFile); try { // // verdict = reportGenerator.generateResult(); } catch (Exception e) { e.printStackTrace(); Alert.raise(e, "Problem when generating results"); } this.outFilePath = reportFile.getAbsolutePath(); // this.verdict = verdict; newLastAnalysisResult(new MixScriptStepAnalysisResult(getFlashFileDigest(), outFilePath, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; }
From source file:com.orange.atk.atkUI.anaMixScript.MixScriptStep.java
License:Apache License
@Override public void save(Element root, int stepNumber) { Element anaElem = root.addElement(type); anaElem.addAttribute("name", "MixScriptstep_" + stepNumber); anaElem.addAttribute("file", getFlashFilePath()); if (getLogin() != null) { anaElem.addAttribute("login", getLogin()); anaElem.addAttribute("password", getPassword()); }//w w w. j a v a 2 s . c om if (getUseragent() != null) { anaElem.addAttribute("useragent", getUseragent()); } if (getXmlfilepath() != null) { anaElem.addAttribute("configfile", getXmlfilepath()); } }
From source file:com.orange.atk.atkUI.anaScript.JatkStep.java
License:Apache License
@Override // public Verdict analyse(StatusBar statusBar, String profileName, // IAnalysisMonitor monitor) public Verdict analyse(IAnalysisMonitor monitor) { try {// w w w . ja v a 2 s.com check(); init(); } catch (Alert a) { this.outFilePath = null; this.verdict = Verdict.SKIPPED; this.skippedMessage = a.getMessage().trim(); newLastAnalysisResult(new JatkStepAnalysisResult(getFlashFileDigest(), outFilePath, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; } String tempDir = Platform.TMP_DIR; XMLOutput jatkResults = new XMLOutput(tempDir, "jatkresults"); Element flashResultsElem = jatkResults.root(); flashResultsElem.addAttribute("flashfile", jatktestFilePath); Calendar cal = new GregorianCalendar(); String currentDate = cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + cal.get(Calendar.YEAR); flashResultsElem.addAttribute("date", currentDate); flashResultsElem.addAttribute("matosversion", Configuration.getVersion()); try { // init is done each time a test is launch verdict = launchtest(); } catch (Exception e) { Logger.getLogger(this.getClass()).error("Problem running the following test file: " + jatktestFilePath, e); } jatkResults.generate(); File reportFile = null; if (outFilePath != null) { reportFile = new File(outFilePath); } else { reportFile = new File(tempDir, "report.html"); } this.outFilePath = reportFile.getAbsolutePath(); newLastAnalysisResult(new JatkStepAnalysisResult(getFlashFileDigest(), outFilePath, getFlashFileName(), Calendar.getInstance(), verdictAsString.get(verdict), null, null, null, Configuration.getVersion())); return verdict; }
From source file:com.orange.atk.atkUI.anaScript.JatkStep.java
License:Apache License
@Override public void save(Element root, int stepNumber) { Element anaElem = root.addElement(TYPE); anaElem.addAttribute("name", "flashstep_" + stepNumber); anaElem.addAttribute("file", getFlashFilePath()); if (getLogin() != null) { anaElem.addAttribute("login", getLogin()); anaElem.addAttribute("password", getPassword()); }//from ww w . j a v a 2s .c om if (getUseragent() != null) { anaElem.addAttribute("useragent", getUseragent()); } if (getXmlfilepath() != null) { anaElem.addAttribute("configfile", getXmlfilepath()); } }