Package java.io

Examples of java.io.PrintWriter


  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();

    response.setContentType("text/plain");
    PrintWriter writer = response.getWriter();

    HttpSession session = request.getSession();
    UserObject userObject = (UserObject)session.getAttribute("userobject");

    int individualID = userObject.getIndividualID();    // logged in user

    // "sycnContactForm", defined in struts-config-sync.xml
    DynaActionForm contactForm = (DynaActionForm)form;
    SyncUtils syncUtils = new SyncUtils();

    try {
      // check to see if CompanionLink Agent has signed in
      if (syncUtils.checkSession(userObject, contactForm) == false) {
        writer.print("FAIL: You are not logged in.");
        return(null);
      }
     
      // decode all characters that are encoded by CompanionLink Agent
      contactForm = syncUtils.parseSpecialChars(contactForm);

      int contactID = 0;
      String formContactID = (String)contactForm.get("contactID");
      if (formContactID != null && ! formContactID.equals("")) {
        try {
          contactID = Integer.parseInt(formContactID);
        }catch(NumberFormatException nfe){
          writer.print("FAIL: Invalid contact ID specified.");
          return(null);
        }
      }else{
        writer.print("FAIL: Invalid contact ID specified.");
        return(null);
      }
     
      ContactFacadeHome cfh = (ContactFacadeHome)CVUtility.getHomeObject("com.centraview.contact.contactfacade.ContactFacadeHome","ContactFacade");
      ContactFacade remote = (ContactFacade)cfh.create();
      remote.setDataSource(dataSource);

      try {
        // check to see if the user has the right to update this record
        AuthorizationHome authHome = (AuthorizationHome)CVUtility.getHomeObject("com.centraview.administration.authorization.AuthorizationHome", "Authorization");
        Authorization authRemote = (Authorization)authHome.create();
       
        if (! authRemote.canPerformRecordOperation(individualID, "Individual", contactID, 20)) {
          return(null);
        }
      }catch(Exception e){
        System.out.println("[Exception][SyncContactEdit] Exception thrown in editContact(2): " + e);
        //e.printStackTrace();
        return(null);
      }

      ModuleFieldRightMatrix rightsMatrix = userObject.getUserPref().getModuleAuthorizationMatrix();
      HashMap indivFieldRights = rightsMatrix.getFieldRights("Individual");
      HashMap entityFieldRights = rightsMatrix.getFieldRights("Entity");

      IndividualVO individualVO = new IndividualVO();
      IndividualVO individualCurrent = remote.getIndividual(contactID);

      individualVO.setContactID(contactID);
     
      String companyName = (String)contactForm.get("companyName");
      if (companyName != null) {
        if (! companyName.equals("")) {
          // first, check to see if a entity with a matching name exists
          // if yes, then associate this invidivual with that entity
          // if no, then create a new entity, and associate this individual with that entity
          SyncFacadeHome syncHome = (SyncFacadeHome)CVUtility.getHomeObject("com.centraview.syncfacade.SyncFacadeHome", "SyncFacade");
          com.centraview.syncfacade.SyncFacade sfremote = (com.centraview.syncfacade.SyncFacade)syncHome.create();
          sfremote.setDataSource(dataSource);
         
          int newEntityID = sfremote.findCompanyNameMatch(companyName, individualID);

          individualVO.setEntityID(newEntityID);
        }else{
          individualVO.setEntityID(individualCurrent.getEntityID());
        }
      }

      String firstName = (String)contactForm.get("firstName");
      if (firstName != null && ! firstName.equals("") && ((Integer)indivFieldRights.get("firstname")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        individualVO.setFirstName(firstName);
      }else{
        individualVO.setFirstName(individualCurrent.getFirstName());
      }


      String MI = (String)contactForm.get("MI");
      if (MI != null && ! MI.equals("") && ((Integer)indivFieldRights.get("middlename")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        individualVO.setMiddleName(MI);
      }else{
        individualVO.setMiddleName(individualCurrent.getMiddleName());
      }

      String lastName = (String)contactForm.get("lastName");
      if (lastName != null && ! lastName.equals("") && ((Integer)indivFieldRights.get("lastname")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        individualVO.setLastName(lastName);
      }else{
        individualVO.setLastName(individualCurrent.getLastName());
      }

      String title = (String)contactForm.get("title");
      if (title != null && ! title.equals("") && ((Integer)indivFieldRights.get("title")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        individualVO.setTitle(title);
      }else{
        individualVO.setTitle(individualCurrent.getTitle());
      }

      String primaryContact = (String)contactForm.get("primaryContact");
      if (primaryContact != null) { // && ((Integer)indivFieldRights.get("primarycontact")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT)
        if (primaryContact.equals("YES") || primaryContact.equals("NO")) {
          individualVO.setIsPrimaryContact(primaryContact);
        }
      }else{
        individualVO.setIsPrimaryContact(individualCurrent.getIsPrimaryContact());
      }
     
      AddressVO primaryAddress = individualCurrent.getPrimaryAddress();
     
      if (primaryAddress == null) {
        primaryAddress = new AddressVO();
      }
      primaryAddress.setIsPrimary("YES");

      if (((Integer)indivFieldRights.get("address")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        String street1 = (String)contactForm.get("street1");
        if ((street1 != null) && (! street1.equals(""))) {
          primaryAddress.setStreet1(street1);
        }
       
        String street2 = (String)contactForm.get("street2");
        if ((street2 != null) && (! street2.equals(""))) {
          primaryAddress.setStreet2(street2);
        }
       
        String city = (String)contactForm.get("city");
        if ((city != null) && (! city.equals(""))) {
          primaryAddress.setCity(city);
        }
       
        String state = (String)contactForm.get("state");
        if ((state != null) && (!state.equals(""))) {
          primaryAddress.setStateName(state);
        }

        String zipCode = (String)contactForm.get("zipCode");
        if ((zipCode != null) && (! zipCode.equals(""))) {
          primaryAddress.setZip(zipCode);
        }

        String country = (String)contactForm.get("country");
        if ((country != null) && (!country.equals(""))) {
          primaryAddress.setCountryName(country);
        }
       
        individualVO.setPrimaryAddress(primaryAddress);

      }   // end if (((Integer)indivFieldRights.get("address")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT)

      if (((Integer)indivFieldRights.get("contactmethod")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT) {
        // get the current MOC values from the individualCurrent MOC
        // save them in String variables for use below
        String currentWorkPhone   = new String("");
        String currentHomePhone   = new String("");
        String currentFaxPhone    = new String("");
        String currentOtherPhone  = new String("");
        String currentMainPhone   = new String("");
        String currentPagerPhone  = new String("");
        String currentMobilePhone = new String("");
        String currentEmail       = new String("");

        MethodOfContactVO currentWorkVO = null;
        MethodOfContactVO currentHomeVO = null;
        MethodOfContactVO currentFaxVO = null;
        MethodOfContactVO currentOtherVO = null;
        MethodOfContactVO currentMainVO = null;
        MethodOfContactVO currentPagerVO = null;
        MethodOfContactVO currentMobileVO = null;
        MethodOfContactVO currentEmailVO = null;

        Vector currentMOCs = individualCurrent.getMOC();
        if (currentMOCs != null) {
          Enumeration e = currentMOCs.elements();
          while (e.hasMoreElements()) {
            MethodOfContactVO mocVO = (MethodOfContactVO)e.nextElement();
            String syncAs = mocVO.getSyncAs();
            if (syncAs != null && (! syncAs.equals(""))) {
              if (syncAs.equals("Work")) {
                currentWorkPhone = mocVO.getContent();
                currentWorkVO = mocVO;
              }else if (syncAs.equals("Home")){
                currentHomePhone = mocVO.getContent();
                currentHomeVO = mocVO;
              }else if (syncAs.equals("Fax")){
                currentFaxPhone = mocVO.getContent();
                currentFaxVO = mocVO;
              }else if (syncAs.equals("Other")){
                currentOtherPhone = mocVO.getContent();
                currentOtherVO = mocVO;
              }else if (syncAs.equals("Main")){
                currentMainPhone = mocVO.getContent();
                currentMainVO = mocVO;
              }else if (syncAs.equals("Pager")){
                currentPagerPhone = mocVO.getContent();
                currentPagerVO = mocVO;
              }else if (syncAs.equals("Mobile")){
                currentMobilePhone = mocVO.getContent();
                currentMobileVO = mocVO;
              }   // end if (syncAs.equals("Work"))
            }else if (mocVO.getMocType() == 1 && mocVO.getIsPrimary().equals("YES")){
              currentEmail = mocVO.getContent();
              currentEmailVO = mocVO;
            }   // end if (syncAs != null && (! syncAs.equals("")))
          }   // end while (e.hasMoreElements())
        }   // end if (currentMOCS != null)


        Vector newMOCs = new Vector();

        // now, check to see what SyncAs values we were passed,
        // if a given value is not null, then check to see if
        // there is an existing value for that field in the db:
        // (check "currentXxxVO" where "Xxx" equals one of the
        // syncAs types [Work, Home, Fax, etc]). If currentXxxVO
        // is null, create a new MethodOfContactVO object, and set
        // the appropriate values, then add that object to the
        // individualVO using setMOC(). Else, update the "content"
        // field and updated field on the currentXxxVO, and pass
        // that object to individualVO.setMOC();
        String workPhone = (String)contactForm.get("workPhone");
        if (workPhone != null && (! workPhone.equals(""))) {
          if (currentWorkVO == null) {
            MethodOfContactVO workPhoneVO = new MethodOfContactVO();
            workPhoneVO.setContent(workPhone);
            workPhoneVO.setSyncAs("Work");
            workPhoneVO.setMocType(Constants.MOC_WORK);
            newMOCs.add(workPhoneVO);
          }else{
            currentWorkVO.setContent(workPhone);
            currentWorkVO.updated(true);
            currentWorkVO.added(false);
            currentWorkVO.delete(false);
            newMOCs.add(currentWorkVO);
          }
        }

        String homePhone = (String)contactForm.get("homePhone");
        if (homePhone != null && (! homePhone.equals(""))) {
          if (currentHomeVO == null) {
            MethodOfContactVO homePhoneVO = new MethodOfContactVO();
            homePhoneVO.setContent(homePhone);
            homePhoneVO.setSyncAs("Home");
            homePhoneVO.setMocType(Constants.MOC_HOME);
            newMOCs.add(homePhoneVO);
          }else{
            currentHomeVO.setContent(homePhone);
            currentHomeVO.updated(true);
            currentHomeVO.added(false);
            currentHomeVO.delete(false);
            newMOCs.add(currentHomeVO);
          }
        }

        String faxPhone = (String)contactForm.get("faxPhone");
        if (faxPhone != null && (! faxPhone.equals(""))) {
          if (currentFaxVO == null) {
            MethodOfContactVO faxPhoneVO = new MethodOfContactVO();
            faxPhoneVO.setContent(faxPhone);
            faxPhoneVO.setSyncAs("fax");
            faxPhoneVO.setMocType(Constants.MOC_FAX);
            newMOCs.add(faxPhoneVO);
          }else{
            currentFaxVO.setContent(faxPhone);
            currentFaxVO.updated(true);
            currentFaxVO.added(false);
            currentFaxVO.delete(false);
            newMOCs.add(currentFaxVO);
          }
        }
       
        String otherPhone = (String)contactForm.get("otherPhone");
        if (otherPhone != null && (! otherPhone.equals(""))) {
          if (currentOtherVO == null) {
            MethodOfContactVO otherPhoneVO = new MethodOfContactVO();
            otherPhoneVO.setContent(otherPhone);
            otherPhoneVO.setSyncAs("other");
            otherPhoneVO.setMocType(Constants.MOC_OTHER);
            newMOCs.add(otherPhoneVO);
          }else{
            currentOtherVO.setContent(otherPhone);
            currentOtherVO.updated(true);
            currentOtherVO.added(false);
            currentOtherVO.delete(false);
            newMOCs.add(currentOtherVO);
          }
        }

        String mainPhone = (String)contactForm.get("mainPhone");
        if (mainPhone != null && (! mainPhone.equals(""))) {
          if (currentMainVO == null) {
            MethodOfContactVO mainPhoneVO = new MethodOfContactVO();
            mainPhoneVO.setContent(mainPhone);
            mainPhoneVO.setSyncAs("main");
            mainPhoneVO.setMocType(Constants.MOC_MAIN);
            newMOCs.add(mainPhoneVO);
          }else{
            currentMainVO.setContent(mainPhone);
            currentMainVO.updated(true);
            currentMainVO.added(false);
            currentMainVO.delete(false);
            newMOCs.add(currentMainVO);
          }
        }

        String pagerPhone = (String)contactForm.get("pagerPhone");
        if (pagerPhone != null && (! pagerPhone.equals(""))) {
          if (currentPagerVO == null) {
            MethodOfContactVO pagerPhoneVO = new MethodOfContactVO();
            pagerPhoneVO.setContent(pagerPhone);
            pagerPhoneVO.setSyncAs("pager");
            pagerPhoneVO.setMocType(Constants.MOC_PAGER);
            newMOCs.add(pagerPhoneVO);
          }else{
            currentPagerVO.setContent(pagerPhone);
            currentPagerVO.updated(true);
            currentPagerVO.added(false);
            currentPagerVO.delete(false);
            newMOCs.add(currentPagerVO);
          }
        }

        String mobilePhone = (String)contactForm.get("mobilePhone");
        if (mobilePhone != null && (! mobilePhone.equals(""))) {
          if (currentMobileVO == null) {
            MethodOfContactVO mobilePhoneVO = new MethodOfContactVO();
            mobilePhoneVO.setContent(mobilePhone);
            mobilePhoneVO.setSyncAs("mobile");
            mobilePhoneVO.setMocType(Constants.MOC_MOBILE);
            newMOCs.add(mobilePhoneVO);
          }else{
            currentMobileVO.setContent(mobilePhone);
            currentMobileVO.updated(true);
            currentMobileVO.added(false);
            currentMobileVO.delete(false);
            newMOCs.add(currentMobileVO);
          }
        }

        String email = (String)contactForm.get("email");
        if (email != null && (! email.equals(""))) {
          if (currentEmailVO == null) {
            MethodOfContactVO emailVO = new MethodOfContactVO();
            emailVO.setContent(email);
            emailVO.setMocType(Constants.MOC_EMAIL);    // 1 == "email"
            emailVO.setIsPrimary("YES")// always set as the primary email address
            newMOCs.add(emailVO);
          }else{
            currentEmailVO.setContent(email);
            currentEmailVO.updated(true);
            currentEmailVO.added(false);
            currentEmailVO.delete(false);
            newMOCs.add(currentEmailVO);
          }
        }
        individualVO.setMoc(newMOCs);
      }   // end if (((Integer)indivFieldRights.get("contactmethod")).intValue() < ModuleFieldRightMatrix.VIEW_RIGHT)

      // now check notes
      String noteContent = (String)contactForm.get("notes");
      if (noteContent != null)
      {
        // ok, here's the tricky part. We need to take this content,
        // parse it into individual notes, and figure out which to
        // change/delete/create. This could prove troublesome...
        NoteHome noteHome = (NoteHome)CVUtility.getHomeObject("com.centraview.note.NoteHome", "Note");
        Note noteRemote = (Note)noteHome.create();
        noteRemote.setDataSource(dataSource);

        NoteVO noteVO = new NoteVO();

        // the "title" of the note will be the first 22 characters of the content,
        // plus "...", unless the content is less than 22 characters, in which case
        // it will be the same as the content...
        String noteTitle = "";
        if (noteContent.length() > 22)
        {
          noteTitle = noteContent.substring(0, 22) + "...";
        }else{
          noteTitle = noteContent;
        }
       
        noteVO.setTitle(noteTitle);
        noteVO.setDetail(noteContent);
        noteVO.setPriority(NoteVO.NP_MEDIUM);
        noteVO.setCreatedBy(individualID);
        noteVO.setOwner(individualID);
        noteVO.setRelateEntity(individualVO.getEntityID());
        noteVO.setRelateIndividual(contactID);
       
        try
        {
          noteRemote.addNote(individualID, noteVO);
        }catch(NoteException ne){
          // TODO: clean up this NoteException handling
          System.out.println("[Exception][ContactAdd] Note Exception caught!: " + ne);
          //ne.printStackTrace();
        }
        // ..whew! That was interesting! At least we're finished now ;-)
      }
     
      individualVO.setContactType(2);
      remote.updateIndividual(individualVO, individualID);//Integer.parseInt(contactID));
      writer.print(contactID);
     
      // we need to make the IndividualList dirty, so that the next time
      // it is viewed, it is refreshed and contains the record we just added
      ListGenerator lg = ListGenerator.getListGenerator(dataSource);
      lg.makeListDirty("Individual");
View Full Code Here


  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException,CommunicationException, NamingException {

    // let's test printing directly to stdout
    response.setContentType("text/plain"); // or text/xml
    PrintWriter writer = response.getWriter();
   
    HttpSession session = request.getSession();
    String sessionID = session.getId();
    ActivityDeleteHandler requestForm = (ActivityDeleteHandler) form;
    UserObject userobject = ( UserObject ) session.getAttribute("userobject" );
    int individualID = userobject.getIndividualID();
   
    String activityID = requestForm.getActivityID(); //request.getParameter( "activityid" );
    String sessionid = requestForm.getSessionID(); //request.getParameter( "sessionid" );

    //session facade object created
    SyncFacade syncfacade = new SyncFacade();
    String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
    syncfacade.setDataSource(dataSource);
    boolean adminstratorUserFlag = false;
    String userType = userobject.getUserType();
   
    if(userType != null && userType.equalsIgnoreCase("ADMINISTRATOR")){
      adminstratorUserFlag = true;
    }
   
    // check session matching
    if (userobject.getSessionID().equals(sessionid))
    {
        String result = syncfacade.deleteActivity(individualID , activityID, adminstratorUserFlag);
        writer.print(result);
    } //end of if statement
    else
    {
      System.out.println("[Sync] Sync failed because sessionID is not valid");
      writer.print("FAIL");
    } //end of else statement
   
    return(null);
  }   // end execute()
View Full Code Here

  {
    final String dataSource = Settings.getInstance().getSiteInfo(
        CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();

    response.setContentType("text/plain");
    PrintWriter writer = response.getWriter();
    // getting user object from session
    HttpSession session = request.getSession();
    UserObject userobjectd = (UserObject)session.getAttribute("userobject");

    // get the user's preference for sync'ing as private or default privileges
    UserPrefererences userPrefs = userobjectd.getUserPref();
    TimeZone tz = TimeZone.getTimeZone(userPrefs.getTimeZone());
    Locale locale = request.getLocale();
    String prefValue = userPrefs.getSyncAsPrivate();
    boolean syncAsPrivate = (prefValue != null && prefValue.equals("YES")) ? true : false;

    // date format for incoming dates: 2004-01-13 15:00:00
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // date format for writing to the form should be in the format based on
    // locale
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, locale);

    ActivityAddHandler requestForm = (ActivityAddHandler)form;
    String sessionID = requestForm.getSessionID();

    // check sessionid is matching or not
    if (userobjectd.getSessionID().equals(sessionID)) {
      ActivityForm activityForm = new ActivityForm();
      activityForm.setLocale(locale);
      String priority = requestForm.getPriority();

      // this is the string that we'll pass to the activityform
      // set to 2 (medium) by default
      String detailpriority = "2";

      if (priority != null) {
        // set the String integer value based on the String string value
        // (confused yet?)
        if (priority.equals("High")) {
          detailpriority = "1";
        } else if (priority.equals("Low")) {
          detailpriority = "3";
        }
      }

      String detailstatus = requestForm.getStatus();

      if (detailstatus == null) {
        detailstatus = "1";
      }

      if (detailstatus != null && !detailstatus.equals("")) {
        if (detailstatus.equals("Pending")) {
          detailstatus = "1";
        } else if (detailstatus.equals("Completed")) {
          detailstatus = "2";
        }
      }

      String detailtitle = requestForm.getTitle();
      String detaildetail = requestForm.getDescription();

      // startdate
      Calendar start = new GregorianCalendar(tz, locale);
      String activityStartDate = requestForm.getStartDateTime();
      if (activityStartDate != null && (!activityStartDate.equals(""))) {
        try {
          Date dd = simpleDateFormat.parse(activityStartDate);
          start.setTime(dd);
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }
      activityForm.setActivityStartDate(df.format(start.getTime()));
      activityForm.setActivityStartTime(tf.format(start.getTime()));

      // enddate
      Calendar end = new GregorianCalendar(tz, locale);
      String activityenddate = requestForm.getEndDateTime();
      if (activityenddate != null && (!activityenddate.equals(""))) {
        try {
          Date dd = simpleDateFormat.parse(activityenddate);
          end.setTime(dd);
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }
      activityForm.setActivityEndDate(df.format(end.getTime()));
      activityForm.setActivityEndTime(tf.format(end.getTime()));

      activityForm.setActivityPriority(detailpriority);
      activityForm.setActivityStatus(detailstatus);
      activityForm.setActivityTitle(detailtitle);
      activityForm.setActivityDetail(detaildetail);

      // alarm date time
      String alarmDateTime = requestForm.getAlarmDateTime(); // alarmDateTime
      // ="01/09/2003";
      if (alarmDateTime != null && (!alarmDateTime.equals(""))) {
        try {
          Date d = simpleDateFormat.parse(alarmDateTime);
          GregorianCalendar remind = new GregorianCalendar();
          remind.setTime(d);
          activityForm.setActivityRemindDate(df.format(remind.getTime()));
          activityForm.setActivityReminder("on");
        } catch (Exception e) {
          logger.error("[execute]: Exception", e);
        }
      }

      // now, add the Activity to the database using our SyncFacade bean
      String linkCompany = requestForm.getLinkCompany();
      if (linkCompany == null) {
        activityForm.setLinkCompany(linkCompany);
      }

      // create an instance of our SyncFacade EJB
      SyncFacade syncfacade = new SyncFacade();
      syncfacade.setDataSource(dataSource);

      // now, add the Activity to the database using our SyncFacade bean
      String activitytype = requestForm.getType();
      if (activitytype == null) {
        activitytype = "Appointment";
      }
      String result = "";

      int individualID = userobjectd.getIndividualID();
      // Appointment
      if (activitytype.equals("Appointment")) {
        activityForm.setActivityType("1");
      }

      // Call
      if (activitytype.equals("Call")) {
        activityForm.setActivityType("2");
      }

      // Meeting
      if (activitytype.equals("Meeting")) {
        activityForm.setActivityType("5");
      }

      // ToDo
      if (activitytype.equals("To Do")) {
        activityForm.setActivityType("6");
      }

      // NextAction
      if (activitytype.equals("Next Action")) {
        activityForm.setActivityType("7");
      }

      result = syncfacade.addActivity(activityForm, individualID);

      com.centraview.syncfacade.SyncFacade sfremote = null;
      try {
        SyncFacadeHome syncHome = (SyncFacadeHome)CVUtility.getHomeObject(
            "com.centraview.syncfacade.SyncFacadeHome", "SyncFacade");
        sfremote = syncHome.create();
        sfremote.setDataSource(dataSource);
      } catch (Exception e) {
        logger.error("[execute]: Exception", e);
        writer.print("FAIL");
        return (null);
      }

      // Check to see if the user's preference is to create sync'ed
      // records as private. If so, delete all records from recordauthorisation
      // and publicrecords tables that link to the newly created records.
      if (syncAsPrivate) {
        ArrayList recordIDs = new ArrayList();
        try {
          recordIDs.add(new Integer(result));
        } catch (NumberFormatException nfe) {
          // don't need to do anything, because we obviously didn't add an
          // activity successfully.
          System.out.println("\n\n\nCAUGHT A NumberFormatException!!!!\n\n\n");
        }
        sfremote.markRecordsPrivate(3, recordIDs);
      }

      // we need to make all the Activities lists dirty, so that the next time
      // they are viewed, they are refreshed and contain the record we just
      // added
      ListGenerator lg = ListGenerator.getListGenerator(dataSource);
      lg.makeListDirty("MultiActivity");
      lg.makeListDirty("AllActivity");
      lg.makeListDirty("Appointment");
      lg.makeListDirty("Call");
      lg.makeListDirty("Meeting");
      lg.makeListDirty("NextAction");
      lg.makeListDirty("ToDo");

      // Now we check to see if this is a recurring activity.
      // Check the "recurrenceType" field. If it is not null,
      // then process the other recurring fields "every" and "on".
      // Then call the SyncFacadeEJB to add the recurring data
      // to the recurrence table.
      String recurrenceType = requestForm.getRecurrenceType();

      if (result != null && !result.equals("")) {
        // only do this if we actually created an activity above
        if (recurrenceType != null && !recurrenceType.equals("")) {
          // this is a recurring activity, get the other recurring fields
          String every = requestForm.getEvery();
          String recurrOn = requestForm.getOn();

          // NOTE: we do not care about recurringStartDate anymore, only copy
          // startDateTime into recurringStartDate
          String recurringStartDateString = requestForm.getStartDateTime();
          String recurringEndDateString = requestForm.getRecurrenceEndDate();

          Date recurringStartDate = null;
          Date recurringEndDate = null;

          try {
            recurringStartDate = simpleDateFormat.parse(recurringStartDateString);
            if (recurringEndDateString != null) {
              recurringEndDate = simpleDateFormat.parse(recurringEndDateString);
            } else {
              recurringEndDate = simpleDateFormat.parse("2099-12-31 00:00:00");
            }

            // NOTE: There is a bug in the CompanionLink Client API, that is
            // sending us the day of the month in the "every" field, instead of
            // the month of the year; when the recurring type is Yearly. To fix
            // this issue, we now get the month of the year from the start date,
            // and set every equal to that value. When CompanionLink addresses
            // this issue correctly, we can remove this hack.
            if (recurrenceType.equals("YEAR")) {
              Calendar recurStart = new GregorianCalendar(tz, locale);
              recurStart.setTime(recurringStartDate);
              every = String.valueOf(recurStart.get(Calendar.MONTH));
            }
            // END HACK for yearly bug from CompanionLink

            // next line returns boolean, but there's no real reason to check.
            // (since we can't ROLLBACK)
            sfremote.setRecurringFields(new Integer(result).intValue(), recurrenceType,
                new Integer(every).intValue(), new Integer(recurrOn).intValue(),
                recurringStartDate, recurringEndDate);
          } catch (Exception de) {
            logger.error("[Exception][(Sync)ActivityAdd]", de);
          }
        }
      }

      writer.print(result);
    } else {
      logger.error("Broken Session on sync.");
      writer.print("FAIL");
    }
    return (null);
  } // end execute() method
View Full Code Here

          }
         
          if ( poop_file != null ){
           
            try{
              pw = new PrintWriter( poop_file );
           
              pw.print( buffer.toString());
             
            }catch( Throwable e ){
            }
View Full Code Here

  writePluginProperties(
    File    target,
    String[]  lines )
  {
    try{
      PrintWriter pw = null;
     
      try{
        target.getParentFile().mkdirs();
       
        pw = new PrintWriter(new FileWriter(target));
 
        for (int i=0;i<lines.length;i++){
       
          pw.println( lines[i] );
        }
       
        pw.println( "plugin.install_if_missing=yes" );
       
      }finally{
 
        if ( pw != null ){
 
          pw.close();
        }
      }

      if (!target.exists()) {
View Full Code Here

     * Attempt to send args via socket connection.
     * @return true if successful, false if connection attempt failed
     */
    public boolean sendArgs() {
      Socket sck = null;
      PrintWriter pw = null;
      try {
        String msg = "StartSocket: passing startup args to already-running Azureus java process listening on [127.0.0.1: 6880]";
       
          // DON'T USE LOGGER here as we DON't want to initialise all the logger stuff
          // and in particular AEDiagnostics config dirty stuff!!!!
       
        System.out.println( msg );
        
        sck = new Socket("127.0.0.1", 6880);
        
          // NOTE - this formatting is also used by AzureusCoreSingleInstanceClient and other org.gudy.azureus2.ui.common.Main.StartSocket
       
        pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream(),Constants.DEFAULT_ENCODING));
        
        StringBuffer buffer = new StringBuffer(AzureusCoreSingleInstanceClient.ACCESS_STRING + ";args;");
        
        for(int i = 0 ; i < args.length ; i++) {
          String arg = args[i].replaceAll("&","&&").replaceAll(";","&;");
          buffer.append(arg);
          buffer.append(';');
        }
        
        pw.println(buffer.toString());
        pw.flush();
       
        return true;
      }
      catch(Exception e) {
        e.printStackTrace();
        Debug.printStackTrace( e );
        return false//there was a problem connecting to the socket
      }
      finally {
        try {
          if (pw != nullpw.close();
        }
        catch (Exception e) {}
       
        try {
          if (sck != null)   sck.close();
View Full Code Here

      showDHTStats( ci );
   
    } else if (subCommand.equalsIgnoreCase("nat") || subCommand.equalsIgnoreCase("n")) {

      IndentWriter  iw = new IndentWriter( new PrintWriter( ci.out ));
     
      iw.setForce( true );
     
      NetworkAdmin.getSingleton().logNATStatus( iw );
   
    } else if (subCommand.equalsIgnoreCase("stats") || subCommand.equalsIgnoreCase("s")) {

      String  pattern = AzureusCoreStats.ST_ALL;
     
      if( args.size() > 0 ){
       
        pattern = (String)args.get(0);
       
        if ( pattern.equals("*")){
         
          pattern = ".*";
        }
      }
   
      if ( args.size() > 1 ){
       
        AzureusCoreStats.setEnableAverages(((String)args.get(1)).equalsIgnoreCase( "on" ));
      }
     
      java.util.Set  types = new HashSet();
     
      types.add( pattern );
     
      Map  reply = AzureusCoreStats.getStats( types );
     
      Iterator  it = reply.entrySet().iterator();
     
      List  lines = new ArrayList();
     
      while( it.hasNext()){
       
        Map.Entry  entry = (Map.Entry)it.next();
       
        lines.add( entry.getKey() + " -> " + entry.getValue());
      }
     
      Collections.sort( lines );
     
      for ( int i=0;i<lines.size();i++){
       
        ci.out.println( lines.get(i));
      }
    } else if (subCommand.equalsIgnoreCase("diag") || subCommand.equalsIgnoreCase("z")) {

      try{
        ci.out.println( "Writing diagnostics to file 'az.diag'" );
       
        FileWriter  fw = new FileWriter( "az.diag" );
       
        PrintWriter  pw = new PrintWriter( fw );
       
        AEDiagnostics.generateEvidence( pw );
       
        pw.flush();
       
        fw.close();
     
      }catch( Throwable e ){
       
View Full Code Here

  }
 
  public static class StartSocket {
    public StartSocket(String args[]) {
      Socket sck = null;
      PrintWriter pw = null;
      try {
        System.out.println("StartSocket: passing startup args to already-running process.");
       
    // NOTE - this formatting is also used by AzureusCoreSingleInstanceClient and other org.gudy.azureus2.ui.swt.StartSocket
       
        sck = new Socket("127.0.0.1",6880);
        pw = new PrintWriter(new OutputStreamWriter(sck.getOutputStream()));
        StringBuffer buffer = new StringBuffer(AzureusCoreSingleInstanceClient.ACCESS_STRING+";args;");
        for(int i = 0 ; i < args.length ; i++) {
          String arg = args[i].replaceAll("&","&&").replaceAll(";","&;");
          buffer.append(arg);
          buffer.append(';');
        }
        pw.println(buffer.toString());
        pw.flush();
      } catch(Exception e) {
        e.printStackTrace();
      } finally {
        try {
          if (pw != null)
            pw.close();
        } catch (Exception e) {
        }
        try {
          if (sck != null)
            sck.close();
View Full Code Here

          log.appendText("[" + prefix.toUpperCase() + "] ");
        }
        log.appendText(message + "\n");
        if (t != null) {
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          t.printStackTrace(pw);
          log.appendText(sw.toString() + "\n");
        }
      }
    });
View Full Code Here

  }
 
  public void
  print()
  {
    PrintWriter  pw = new PrintWriter( System.out );
   
    print( pw );
   
    pw.flush();
  }
View Full Code Here

TOP

Related Classes of java.io.PrintWriter

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.