Esempio n. 1
0
 /**
  * Duplicated in tools.ReleaseQuality
  *
  * @param args
  */
 public static void main(String[] args) {
   if (args.length != 1) {
     Application_GUI.warning(
         __("Bad parameters list: need xml_file_name;"), __("RELEASE QUALITY"));
     return;
   }
   File xml = new File(args[0]);
   if (!xml.isFile()) {
     Application_GUI.warning(
         __("Bad parameters list: need existing xml_file_name;"), __("RELEASE QUALITY"));
     return;
   }
   D_ReleaseQuality[] rq = parseXML(xml);
   Encoder enc = Encoder.getEncoder(rq);
   System.out.println(new String(Base64Coder.encode(enc.getBytes())));
 }
Esempio n. 2
0
 public void _run() {
   for (; ; ) {
     if (stop) return;
     synchronized (saver_thread_monitor) {
       D_DirectoryEntry de = need_saving_next();
       if (de != null) {
         Application_GUI.ThreadsAccounting_ping("Saving");
         need_saving_remove(de.globalIDhash, de.instance);
         // try 3 times to save
         for (int k = 0; k < 3; k++) {
           try {
             de.update();
             break;
           } catch (P2PDDSQLException e) {
             e.printStackTrace();
             synchronized (this) {
               try {
                 wait(SAVER_SLEEP_ON_ERROR);
               } catch (InterruptedException e2) {
                 e2.printStackTrace();
               }
             }
           }
         }
       } else {
         Application_GUI.ThreadsAccounting_ping("Nothing to do!");
       }
     }
     synchronized (this) {
       try {
         wait(SAVER_SLEEP);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   }
 }
Esempio n. 3
0
	private void handleChoiceEvent(Object source) {
		//boolean DEBUG = true;
		if(DEBUG) out.println("JustificationEditor:handleFieldEvent: start");
		/*
		String creationTime;
		if(vote_date_field != null) {
			creationTime = vote_date_field.getText();
		}else{
			creationTime = Util.getGeneralizedTime();
		}
		*/
		if((this.vote_date_field==source)||(this.vote_date_field.getDocument()==source)) {
			if(DEBUG) out.println("JustificationEditor:handleFieldEvent: date title");
			String new_text = this.vote_date_field.getText();
			Calendar cal = Util.getCalendar(new_text);
			if(cal == null) return;
			this.signature.creation_date = cal;
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_dategen_field==source) {
			this.signature.creation_date = Util.CalendargetInstance();
			this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_newjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio");
			this.just_old_just_field.setEnabled(false);
			//setChoiceOldJustification(creationTime);
			//enable_just();
			if(motionEditor!=null){
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in motioneditor");
				motionEditor.enableNewJustification(true);
				signature.justification_ID = motionEditor.getNewJustificationID();
				signature.global_justification_ID = null;
			}else{
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in justeditor");
				this.justificationEditor.make_new();
				this.enable_just();
				signature.justification_ID = justification.justification_ID;
				signature.global_justification_ID = null;
			}
			return;
		}
		if(this.vote_oldjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice oldjust_radio");
			this.just_old_just_field.setEnabled(true);
			setChoiceOldJustification();
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			return;
		}
		if(this.vote_nojust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice nojust_radio");
			this.just_old_just_field.setEnabled(false);
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			try{
				signature.justification_ID = null;
				signature.global_justification_ID = null;
				//this.signature.creation_date = Util.getCalendar(creationTime);
				this.signature.setEditable();
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}	
		}
		if(just_old_just_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice old_just_combo");
			//if(DEBUG) Util.printCallPath("Linux tracing");
			setChoiceOldJustification();
			return;
		}
		if(this.vote_choice_field == source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice vote_choice_field combo");
			setChoice();
			return;
		}
		if((just_submit_field == source)) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: submit");
			try {
				long j_id=-1;
				D_Justification justification =null;
				if(signature.choice==null){
					Application_GUI.warning(_("No voting choice made.\nPlease return and make a voting choice."), _("No Choice Made"));
					return;
				}
				if(vote_newjust_field.isSelected()) {
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification");
					justification = justificationEditor.just;
					if(motionEditor!=null){
						justification = motionEditor.getNewJustification();
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from motionEditor="+justification);
					}else{
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from justEditor="+justification);						
					}
					
					if(justification.global_constituent_ID==null){
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: reget justification");
						justification.global_constituent_ID = GUI_Swing.constituents.tree.getModel().getConstituentGIDMyself();
						justification.constituent_ID = Util.getStringID(GUI_Swing.constituents.tree.getModel().getConstituentIDMyself());
						if(justification.global_constituent_ID==null) {
							Application_GUI.warning(_("You should first select a constituent identity for this organization!"), _("No Constituent ID for this org!"));
							return;
						}
					}

					
					justification.global_justificationID = justification.make_ID();
					justification.sign();
					j_id = justification.storeVerified(DEBUG);
					if(j_id<=0){
						if(_DEBUG) out.println("VoteEditor:handleFieldEvent: failed saving no new justif");
						return;					
					}
				}else{
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: no new justification selected");
				}
				
				//signature = signature;
				//signature.global_motion_ID = null;
				//signature.motion_ID = justificationEditor.just.motion_ID;
				if(vote_newjust_field.isSelected()) {
					signature.global_justification_ID = justification.global_justificationID;
					signature.justification_ID = Util.getStringID(j_id);//justificationEditor.just.justification_ID;
				}
				signature.global_vote_ID = signature.make_ID();
				
				D_Vote old = new D_Vote(signature.global_vote_ID);
				if(old.vote_ID!=null){
					String old_date = Encoder.getGeneralizedTime(old.creation_date);
					String new_date = Encoder.getGeneralizedTime(signature.creation_date);
					if(old_date.equals(new_date)){
						int attack = Application_GUI.ask(
								_("Are you sure you want to create a new vote \n" +
								"with the same date as your previous vote? \n" +
								"This can amount to an attack where you give different people different votes!\n" +
								"Except if they order such votes by signature (to be implemented)\n" +
								"On selecting NO, we will update the creation date to now."),
								_("Votes from you on the same issue and with same date!"), JOptionPane.YES_NO_CANCEL_OPTION);
						switch(attack) {
						case 0: //YES
							break;
						case 1: // NO
							signature.creation_date = Util.CalendargetInstance();
							this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
							break;
						case 2: // CANCEL
						default:
							return;
						}
					}
				}
				
				signature.sign();
				long v_id = this.signature.storeVerified();
				if(v_id<=0){
					if(_DEBUG) out.println("VoteEditor:handleFieldEvent: submit sign got no local ID");
					return;
				}
				
				/*
				justificationEditor.just.global_justificationID = justificationEditor.just.make_ID();
				justificationEditor.just.sign();
				long id = justificationEditor.just.storeVerified();
				if(id<=0) return;
				*/
				disable_it();
				justificationEditor.disable_it();
				try{
					D_Motion m = new D_Motion(Util.lval(signature.motion_ID));
					m.broadcasted = true;
					m.storeVerified();
				}catch(Exception e){e.printStackTrace();}
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
		}
	}
	@SuppressWarnings("unchecked")
	public void handleFieldEvent(Object source, DocumentEvent evt) {
		
		if(evt!=null){
			this.notifyChange(evt);
			return;
		}else{
			/*
			evt = new DocumentEvent(){ //placeholder for null
				public Document mySource = null;
				@Override
				public ElementChange getChange(Element arg0) {
					return null;
				}
				@Override
				public Document getDocument() {
					return mySource;
				}
				@Override
				public int getLength() {
					return 0;
				}
				@Override
				public int getOffset() {
					return 0;
				}
				@Override
				public EventType getType() {
					return null;
				}};
				*/
		}
		
		//boolean DEBUG = true;
		if(this.setTxtMode==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: setText");
			switchMode(D_Document.TXT_BODY_FORMAT);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.setHTMMode==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: setHTM");
			switchMode(D_Document.HTM_BODY_FORMAT);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.sync_changes==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: sync");
			editor.updateDoc(data);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.load_field==source) {
			if(DEBUG)System.err.println("ControlPane:actionImport: import file");
			int returnVal = MotionEditor.fd.showOpenDialog(this);
			if(DEBUG)System.err.println("ControlPane:actionImport: Got: selected");
	        if (returnVal == JFileChooser.APPROVE_OPTION) {
	        	if(DEBUG)System.err.println("ControlPane:actionImport: Got: ok");
	            File file = MotionEditor.fd.getSelectedFile();
	            if(!file.exists()){
	            	Application_GUI.warning(_("The file does not exists: "+file),_("Importing Address")); return;
	            }
	            String ext = Util.getExtension(file);
	            if(ext!=null) ext = ext.toLowerCase();
	            try {
	            	boolean _DEBUG = true;
					if("pdf".equals(ext)) {
	            		if(DEBUG)System.err.println("ControlPane:actionImport: Got: pdf");
	            		try {
	            			// File f = new File("/home/msilaghi/CS_seminar_flyer.pdf");
	            			InputStream in = new FileInputStream(file); // "/home/msilaghi/CS_seminar_flyer.pdf");
	            			if(file.length() > DocumentEditor.MAX_PDF) {
	            				if(_DEBUG) System.out.println("OrgEditor: getText: bin size="+file.length()+" vs "+DocumentEditor.MAX_PDF);
	            				Application_GUI.warning(_("File too large! Current Limit:"+" "+file.length()+"/"+DocumentEditor.MAX_PDF),
	            						_("Document too large for import!"));
	            				in.close();
	            				return;
	            			}
	            			byte bin[] = new byte[(int)file.length()];
	            			int off = 0;
	            			do{
	            				int cnt = in.read(bin, off, bin.length-off);
	            				if(cnt == -1) {
	            					if(_DEBUG) System.out.println("OrgEditor: getText: crt="+cnt+" off="+off+"/"+bin.length);
	            					break;
	            				}
	            				off +=cnt;
            					if(_DEBUG) System.out.println("OrgEditor: getText: crt="+cnt+" off="+off+"/"+bin.length);
	            			}while(off < bin.length);
	            			in.close();
	            			if(DEBUG) System.out.println("DocumentEditor: handle: bin size="+bin.length);
	            			String data = Util.stringSignatureFromByte(bin);
	            			if(DEBUG) System.out.println("DocumentEditor: handle: txt size="+data.length());
	            			
	            			setMode(D_Document.PDF_BODY_FORMAT, data);
	            			
							this.notifyChange(evt);
	            		} catch (FileNotFoundException e) {
	            			e.printStackTrace();
	            		} catch (IOException e) {
	            			e.printStackTrace();
	            		}
	            	}else
	            		if(("html".equals(ext)) || ("htm".equals(ext))){
	            			if(_DEBUG)System.err.println("ControlPane:actionImport: Got: html: implement!");
	            			try{
	            				BufferedReader bri = new BufferedReader(new FileReader(file));
								String data = Util.readAll(bri);
								
								setMode(D_Document.HTM_BODY_FORMAT, data);
								
								this.notifyChange(evt);
	            			}catch(Exception e){
	            				e.printStackTrace();
	            			}
	            		}else
	            			if(("txt".equals(ext))){
	            				try{
		            				BufferedReader bri = new BufferedReader(new FileReader(file));
									String data = Util.readAll(bri);
									
									setMode(D_Document.TXT_BODY_FORMAT, data);
									
									this.notifyChange(evt);
		            			}catch(Exception e){
		            				e.printStackTrace();
		            			}
	            			}else
	            				if(_DEBUG)System.err.println("ControlPane:actionImport: Got: "+ext+": implement!");
	            }catch(Exception e){
	            	e.printStackTrace();
	            }
	        }
		}
	}