Package java.io

Examples of java.io.PrintWriter


          mLog.info("Using default menu bar (instead of MacOSXMenuBar) for transportable version.");
        }
        mLog.warning("Could not instantiate MacOSXMenuBar\n" + e.toString());
        if (e.getCause() != null) {
          StringWriter sw = new StringWriter();
          e.getCause().printStackTrace(new PrintWriter(sw));
          mLog.warning(sw.toString());
        }
        mMenuBar = new DefaultMenuBar(this, mStatusBar.getLabel());
        mLog.info("Using default menu bar");
      }
View Full Code Here


     */
    public void invoke(OutContext context, IXMLWriter xmlWriter) throws IOException, WsException {
        xmlWriter.startTagClosed(0, ELEMENT_NAME);
        if (m_includeStackTrace) {
            StringWriter sw = new StringWriter();
            m_throwable.printStackTrace(new PrintWriter(sw));
            xmlWriter.writeTextContent(sw.toString());
        } else {
            xmlWriter.writeTextContent(m_throwable.getClass().getName() + MESSAGE_SEPARATOR
                + m_throwable.getLocalizedMessage());
        }
View Full Code Here

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    // we're going to be printing directly to the client,
    // so let's set the content type and get a PrintWriter
    response.setContentType("text/plain");
    PrintWriter writer = response.getWriter();

    try
    {
      HttpSession session = request.getSession();
     
      if (session != null){
        session.invalidate();
      }
    }catch(java.lang.IllegalStateException e){
      // ok, if an exception occurs, there's nothing we can really do
      // so just print an error to the log and redirect to the login page
      System.out.println("[Exception][LogoutHandler] Exception thrown in execute(): " + e);
    }
   
    writer.print("OK");
   
    return(null);
  }   // end execute()
View Full Code Here

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

    // we're going to be printing directly to the client,
    // so let's set the content type and get a PrintWriter
    response.setContentType("text/plain");
    PrintWriter writer = response.getWriter();

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

    try
    {
      // check the user name and password provided
      boolean loginResult = syncFacade.doLogin(form, request, response);

      if (loginResult != false) {
        // SyncFacade printed the output, don't do anything here.
      }else{
        writer.print("FAIL");
      }   // end if (doLogin() !== false)
    }catch(Exception e){
      writer.print("FAIL");
    }
   
    // we're not forwarding to a jsp, so return null
    return(null);
  }   // end execute()
View Full Code Here

  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 individualIDsession = 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);

      SyncFacadeHome syncHome = (SyncFacadeHome)CVUtility.getHomeObject("com.centraview.syncfacade.SyncFacadeHome", "SyncFacade");
      com.centraview.syncfacade.SyncFacade sfremote = (com.centraview.syncfacade.SyncFacade)syncHome.create();
      sfremote.setDataSource(dataSource);

      // get the list of individuals from the ejb layer
      Collection individualList = sfremote.getIndividualList(individualIDsession);

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

      // individualList shouldn't be null. If it is, there's a problem.
      // SyncFacadeEJB should always return a valid collection (an
      // empty Collection is still a valid Collection, but null is not).
      if (individualList != null)
      {
        // print the header row. Do it even if there are no individuals in the list
        writer.print("ContactID\tlastModified\tcompanyName\tfirstName\tMI\tlastName\ttitle\t");
        writer.print("street1\tstreet2\tcity\tstate\tzipCode\tcountry\t");
        writer.print("email\tworkPhone\thomePhone\tfaxPhone\totherPhone\tmainPhone\t");
        writer.print("pagerPhone\tmobilePhone\tworkPhoneExt\thomePhoneExt\tfaxPhoneExt\t");
        writer.print("otherPhoneExt\tmainPhoneExt\tpagerPhoneExt\tmobilePhoneExt\tnotes\n");

        // we successfully got the IndividualList, let's process it :-)
        if (individualList.size() > 0)
        {
          Iterator it = individualList.iterator();
         
          while (it.hasNext())
          {
            HashMap individualDetails = (HashMap)it.next();

            int individualID = ((Number)individualDetails.get("contactID")).intValue();

            // This hashmap will temporarily hold all field values until
            // we are ready to print them out. It will be helpful to us
            // when we need to encode special characters.
            HashMap record = new HashMap();

            // IndividualID
            record.put("ContactID", String.valueOf(individualID));

            //lastModifiedDate
            record.put("lastModified", syncUtils.formatDate((Timestamp)individualDetails.get("lastModified")));

            // First check field rights privileges (of certain fields),
            // if user has sufficient privilege, print field, if user
            // does not have sufficient privilege, print a "-".

            // ***IMPORTANT!!*** If the user does not have privilege to
            // a given field, CompanionLink expects a "-". Sending a null
            // or blank string will cause CompanionLink to believe this
            // is the CONTENT of the field, and will update the record
            // with that information. It is extremely important to make
            // sure this is done properly.

            // ***IMPORTANT!!*** It is also extremely important to note
            // that we can never set any field to the java NULL value. This
            // will cause "null" to be printed out to the CompanionLink
            // client, in which case CompanionLink will evaluate the String
            // "null" as the content of the field. Therefore, ALWAYS CHECK
            // FOR NULL VALUES BEFORE PRINTING!!! (or adding to our temp
            // HashMap)...

            // companyName
            if (((Integer)entityFieldRights.get("name")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              String companyName = (String)individualDetails.get("companyName");
              record.put("companyName", (companyName != null) ? companyName : "");
            }else{
              record.put("companyName", "-");
            }
           
            // firstName
            if (((Integer)indivFieldRights.get("firstname")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              String firstName = (String)individualDetails.get("firstName");
              record.put("firstName", (firstName != null) ? firstName : "");
            }else{
              record.put("firstName", "-");
            }
           
            // MI
            if (((Integer)indivFieldRights.get("middlename")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              String middleName = (String)individualDetails.get("middleName");
              record.put("MI", (middleName != null) ? middleName : "");
            }else{
              record.put("MI", "-");
            }

            // lastName
            if (((Integer)indivFieldRights.get("lastname")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              String lastName = (String)individualDetails.get("lastName");
              record.put("lastName", (lastName != null) ? lastName : "");
            }else{
              record.put("lastName", "-");
            }

            // title
            if (((Integer)indivFieldRights.get("title")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              String title = (String)individualDetails.get("title");
              record.put("title", (title != null) ? title : "");
            }else{
              record.put("title", "-");
            }

            // Check field rights for address
            if (((Integer)indivFieldRights.get("address")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              // if user has view rights to address, show address data
              String street1 = (String)individualDetails.get("street1");
              record.put("street1", (street1 != null) ? street1 : "");
             
              String street2 = (String)individualDetails.get("street2");
              record.put("street2", (street2 != null) ? street2 : "");
             
              String city = (String)individualDetails.get("city");
              record.put("city", (city != null) ? city : "");
             
              String state = (String)individualDetails.get("state");
              record.put("state", (state != null) ? state : "");
             
              String zipCode = (String)individualDetails.get("zipCode");
              record.put("zipCode", (zipCode != null) ? zipCode : "");
             
              String country = (String)individualDetails.get("country");
              record.put("country", (country != null) ? country : "");
            }else{
              // user does not have field rights for address, so send dashes to CompanionLink
              record.put("street1", "-");
              record.put("street2", "-");
              record.put("city", "-");
              record.put("state", "-");
              record.put("zipCode", "-");
              record.put("country", "-");
            }

            String emailContent = new String("");
            String workPhone    = new String("");
            String workPhoneExt   = new String("");
            String homePhone    = new String("");
            String homePhoneExt   = new String("");
            String faxPhone     = new String("");
            String faxPhoneExt    = new String("");
            String otherPhone   = new String("");
            String otherPhoneExt  = new String("");
            String mainPhone    = new String("");
            String mainPhoneExt   = new String("");
            String pagerPhone   = new String("");
            String pagerPhoneExt  = new String("");
            String mobilePhone  = new String("");
            String mobilePhoneExt = new String("");
           
            if (((Integer)indivFieldRights.get("contactmethod")).intValue() < ModuleFieldRightMatrix.NONE_RIGHT)
            {
              // If the user has privilege to view contact methods (they are not limited
              // individually; ie: "email" cannot be different than "homePhome"), then
              // get the data from the database and stick it in temp variables
              emailContent = (String)individualDetails.get("email");

              // NOTE that for all phone fields, we need to extract the extension
              // and store it in a separate variable because it's a separate field
              workPhone = (String)individualDetails.get("workPhone");
              if (workPhone != null && workPhone.indexOf("EXT") > 0)
              {
                String temp = workPhone;
                workPhone = temp.substring(0, temp.indexOf("EXT"));
                workPhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }
             
              homePhone = (String)individualDetails.get("homePhone");
              if (homePhone != null && homePhone.indexOf("EXT") > 0)
              {
                String temp = homePhone;
                homePhone = temp.substring(0, temp.indexOf("EXT"));
                homePhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }

              faxPhone = (String)individualDetails.get("faxPhone");
              if (faxPhone != null && faxPhone.indexOf("EXT") > 0)
              {
                String temp = faxPhone;
                faxPhone = temp.substring(0, temp.indexOf("EXT"));
                faxPhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }

              otherPhone = (String)individualDetails.get("otherPhone");
              if (otherPhone != null && otherPhone.indexOf("EXT") > 0)
              {
                String temp = otherPhone;
                otherPhone = temp.substring(0, temp.indexOf("EXT"));
                otherPhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }

              mainPhone = (String)individualDetails.get("mainPhone");
              if (mainPhone != null && mainPhone.indexOf("EXT") > 0)
              {
                String temp = mainPhone;
                mainPhone = temp.substring(0, temp.indexOf("EXT"));
                mainPhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }

              pagerPhone = (String)individualDetails.get("pagerPhone");
              if (pagerPhone != null && pagerPhone.indexOf("EXT") > 0)
              {
                String temp = pagerPhone;
                pagerPhone = temp.substring(0, temp.indexOf("EXT"));
                pagerPhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }

              mobilePhone = (String)individualDetails.get("mobilePhone");
              if (mobilePhone != null && mobilePhone.indexOf("EXT") > 0)
              {
                String temp = mobilePhone;
                mobilePhone = temp.substring(0, temp.indexOf("EXT"));
                mobilePhoneExt = temp.substring(temp.indexOf("EXT") + 3, temp.length());
              }
            }else{
              // If the user does NOT have privilege to view contact methods, then
              // set the content of all contact method variables to "-", which tells
              // CompanionLink that this is a restricted field.
              emailContent   = "-";
              workPhone      = "-";
              workPhoneExt   = "-";
              homePhone      = "-";
              homePhoneExt   = "-";
              faxPhone       = "-";
              faxPhoneExt    = "-";
              otherPhone     = "-";
              otherPhoneExt  = "-";
              mainPhone      = "-";
              mainPhoneExt   = "-";
              pagerPhone     = "-";
              pagerPhoneExt  = "-";
              mobilePhone    = "-";
              mobilePhoneExt = "-";
            }

            record.put("email", (emailContent != null) ? emailContent : "");
            record.put("workPhone", (workPhone != null) ? workPhone : "");
            record.put("workPhoneExt", (workPhoneExt != null) ? workPhoneExt : "");
            record.put("homePhone", (homePhone != null) ? homePhone : "");
            record.put("homePhoneExt", (homePhoneExt != null) ? homePhoneExt : "");
            record.put("faxPhone", (faxPhone != null) ? faxPhone : "");
            record.put("faxPhoneExt", (faxPhoneExt != null) ? faxPhoneExt : "");
            record.put("otherPhone", (otherPhone != null) ? otherPhone : "");
            record.put("otherPhoneExt", (otherPhoneExt != null) ? otherPhoneExt : "");
            record.put("mainPhone", (mainPhone != null) ? mainPhone : "");
            record.put("mainPhoneExt", (mainPhoneExt != null) ? mainPhoneExt : "");
            record.put("pagerPhone", (pagerPhone != null) ? pagerPhone : "");
            record.put("pagerPhoneExt", (pagerPhoneExt != null) ? pagerPhoneExt : "");
            record.put("mobilePhone", (mobilePhone != null) ? mobilePhone : "");
            record.put("mobilePhoneExt", (mobilePhoneExt != null) ? mobilePhoneExt : "");

            // notes
            String notes = (String)individualDetails.get("notes");
            record.put("notes", (notes != null) ? notes : "");

            // now encode all strings in the record properly
            record = syncUtils.encodeRecord(record);

            // time to print out the record and move on
            // DO NOT CHANGE THE ORDER OF THESE FIELDS!
            // NOTE that we did not add the "\t" delimiter
            // to each field, but instead we're adding it here
            // as we print out each field. That is because we
            // encode the "record" HashMap as a whole, and part
            // of that encoding encodes tabs into a non-printable
            // character. If we had added the tab to our fields,
            // then we would lose our field delimiter...
            writer.print(record.get("ContactID") + "\t");
            writer.print(record.get("lastModified") + "\t");
            writer.print(record.get("companyName") + "\t");
            writer.print(record.get("firstName") + "\t");
            writer.print(record.get("MI") + "\t");
            writer.print(record.get("lastName") + "\t");
            writer.print(record.get("title") + "\t");
            writer.print(record.get("street1") + "\t");
            writer.print(record.get("street2") + "\t");
            writer.print(record.get("city") + "\t");
            writer.print(record.get("state") + "\t");
            writer.print(record.get("zipCode") + "\t");
            writer.print(record.get("country") + "\t");
            writer.print(record.get("email") + "\t");
            writer.print(record.get("workPhone") + "\t");
            writer.print(record.get("homePhone") + "\t");
            writer.print(record.get("faxPhone") + "\t");
            writer.print(record.get("otherPhone") + "\t");
            writer.print(record.get("mainPhone") + "\t");
            writer.print(record.get("pagerPhone") + "\t");
            writer.print(record.get("mobilePhone") + "\t");
            writer.print(record.get("workPhoneExt") + "\t");
            writer.print(record.get("homePhoneExt") + "\t");
            writer.print(record.get("faxPhoneExt") + "\t");
            writer.print(record.get("otherPhoneExt") + "\t");
            writer.print(record.get("mainPhoneExt") + "\t");
            writer.print(record.get("pagerPhoneExt") + "\t");
            writer.print(record.get("mobilePhoneExt") + "\t");
            writer.print(record.get("notes") + "\n")// NOTE THE NEWLINE HERE!!!
          }   // end while (it.hasNext())  (individualList)

          ListGenerator lg = ListGenerator.getListGenerator(dataSource);
          lg.makeListDirty("Individual");
        }
      }else{
        // individual list was null. Something must have gone wrong.
        writer.print("FAIL: An unknown error occurred.");
        return(null);
      }
    }catch(Exception e){
      System.out.println("[Exception][ContactList] Exception thrown in execute(): " + e);
      // TODO: remove stack trace
View Full Code Here

  public boolean doLogin(ActionForm form, HttpServletRequest request, HttpServletResponse response)
      throws IOException
  {
    String userName = new String("");
    String password = new String("");
    PrintWriter writer = response.getWriter();

    if (form != null) {
      // use the LoginForm bean to get the username and password
      LoginForm LoginForm = (LoginForm)form;

      userName = LoginForm.getUserName();
      password = LoginForm.getPassword();
    } else {
      // if the form wasn't submitted, then the process failed, so return false
      return (false);
    }

    try {
      LoginHome lh = (LoginHome)CVUtility.getHomeObject("com.centraview.login.LoginHome", "Login");
      com.centraview.login.Login remote = lh.create();
      remote.setDataSource(this.dataSource);

      HashMap loginResult = remote.authenticateUser(userName, password);

      if (!loginResult.containsKey("error")) {
        // login was successful, generate a sessionID and stick it in the
        // HttpSession UserObject

        // then generate a sesionID
        HttpSession session = request.getSession();
        String sessionID = session.getId();

        // next, create a UserObject, and pass the sessionID to it
        String uoIndividualID = (String)loginResult.get("individualid");
        String uoFirstName = (String)loginResult.get("firstName");
        String uoLastName = (String)loginResult.get("lastName");
        String uoUserType = (String)loginResult.get("type");

        UserObject userObject = remote.getUserObject(Integer.parseInt(uoIndividualID),
            uoFirstName, uoLastName, uoUserType);
        userObject.setSessionID(sessionID);

        // Please note that the next line has a severe mis-spelling on it.
        // The class name was mis-spelled when it was created, and it was
        // never fixed. So please be careful when trying to use the class
        // "UserPrefererences" - make sure you spell it wrong intentionally
        UserPrefererences userPrefs = userObject.getUserPref();

        AuthorizationHome authHome = (AuthorizationHome)CVUtility.getHomeObject(
            "com.centraview.administration.authorization.AuthorizationHome", "Authorization");
        Authorization authRemote = authHome.create();
        authRemote.setDataSource(this.dataSource);

        ModuleFieldRightMatrix rightsMatrix = authRemote.getUserSecurityProfileMatrix(userObject
            .getIndividualID());

        if (!rightsMatrix.isModuleVisible("Synchronize")) {
          return (false);
        }

        userPrefs.setModuleAuthorizationMatrix(rightsMatrix);
        userObject.setUserPref(userPrefs);

        // now, save the userObject in the request session
        session.setAttribute("userobject", userObject);

        // print the server date/time and sessionID
        Date date = new Date();

        SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentDateTime = dateFormatter.format(date);

        writer.print(currentDateTime + "\n" + sessionID);
        return (true);
      }
      return (false);
    } catch (Exception e) {
      logger.error("[Exception] SyncFacade.doLogin ", e);
View Full Code Here

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

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

    StringBuffer output = new StringBuffer("");

    HttpSession session = request.getSession();
    UserObject userObject = (UserObject)session.getAttribute("userobject");
   
    // get the user's preference for sync'ing as private or default privileges
    UserPrefererences userPrefs = userObject.getUserPref();
    String prefValue = (String)userPrefs.getSyncAsPrivate();
    boolean syncAsPrivate = (prefValue != null && prefValue.equals("YES")) ? true : false;

    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);

      String firstName = (String)contactForm.get("firstName");
      String lastName = (String)contactForm.get("lastName");
      // now validate the form data
      if (firstName == null || firstName.equals(""))
      {
        if (lastName == null || lastName.equals(""))
        {
          return(null);
        }
      }

      String primaryContact = (String)contactForm.get("primaryContact");
      if (! primaryContact.equals("Yes") && ! primaryContact.equals("No"))
      {
        return(null);
      }

      // if CompanionLink Agent did not send us an Entity name,
      // then set the entity name equal to the individual's name
      String companyName = (String)contactForm.get("companyName");
      if (companyName == null || companyName.equals(""))
      {
        companyName = firstName + " " + lastName;
      }

      ContactFacadeHome cfh = (ContactFacadeHome)CVUtility.getHomeObject("com.centraview.contact.contactfacade.ContactFacadeHome","ContactFacade");
      ContactFacade remote = (ContactFacade)cfh.create();
      remote.setDataSource(dataSource);
     
      SyncFacadeHome syncHome = (SyncFacadeHome)CVUtility.getHomeObject("com.centraview.syncfacade.SyncFacadeHome", "SyncFacade");
      com.centraview.syncfacade.SyncFacade sfremote = (com.centraview.syncfacade.SyncFacade)syncHome.create();
      sfremote.setDataSource(dataSource);

      // this will represent the new Individual we are creating
      IndividualVO individualVO = new IndividualVO();

      individualVO.setFirstName(firstName);
      individualVO.setMiddleName((String)contactForm.get("MI"));
      individualVO.setLastName(lastName);
      individualVO.setTitle((String)contactForm.get("title"));
      individualVO.setIsPrimaryContact(primaryContact);
      individualVO.setContactType(2);   // contactType 2 is "Individual"

      AddressVO primaryAddress = new AddressVO();

      primaryAddress.setIsPrimary("YES");
      primaryAddress.setStreet1((String)contactForm.get("street1"));
      primaryAddress.setStreet2((String)contactForm.get("street2"));
      primaryAddress.setCity((String)contactForm.get("city"));
      primaryAddress.setStateName((String)contactForm.get("state"));
      primaryAddress.setZip((String)contactForm.get("zipCode"));
      primaryAddress.setCountryName((String)contactForm.get("country"));
     
      individualVO.setPrimaryAddress(primaryAddress);

      // save email address
      String email = (String)contactForm.get("email");
      if (email != null && ! email.equals(""))
      {
        MethodOfContactVO emailVO = new MethodOfContactVO();
        emailVO.setContent(email);
        emailVO.setMocType(Constants.MOC_EMAIL);   // hardcoded to "Email" type
        emailVO.setIsPrimary("YES")// always set as the primary email address
        individualVO.setMOC(emailVO);
      }

      // set workPhone
      String workPhone = (String)contactForm.get("workPhone");
      if (workPhone != null && (! workPhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO workPhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String workPhoneExt = (String)contactForm.get("workPhoneExt");
        if (workPhoneExt != null && ! workPhoneExt.equals(""))
        {
          workPhone = workPhone + "EXT" + workPhoneExt;
        }
        workPhoneMocVO.setContent(workPhone);
        workPhoneMocVO.setSyncAs("Work");
        workPhoneMocVO.setMocType(Constants.MOC_WORK);   // hardcoded to "Phone" type

        individualVO.setMOC(workPhoneMocVO);
      }

      // set homePhone
      String homePhone = (String)contactForm.get("homePhone");
      if (homePhone != null && (! homePhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO homePhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String homePhoneExt = (String)contactForm.get("homePhoneExt");
        if (homePhoneExt != null && ! homePhoneExt.equals(""))
        {
          homePhone = homePhone + "EXT" + homePhoneExt;
        }
        homePhoneMocVO.setContent(homePhone);
        homePhoneMocVO.setSyncAs("Home");
        homePhoneMocVO.setMocType(Constants.MOC_HOME);   // hardcoded to "Phone" type

        individualVO.setMOC(homePhoneMocVO);
      }

      // set faxPhone
      String faxPhone = (String)contactForm.get("faxPhone");
      if (faxPhone != null && (! faxPhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO faxPhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String faxPhoneExt = (String)contactForm.get("faxPhoneExt");
        if (faxPhoneExt != null && ! faxPhoneExt.equals(""))
        {
          faxPhone = faxPhone + "EXT" + faxPhoneExt;
        }
        faxPhoneMocVO.setContent(faxPhone);
        faxPhoneMocVO.setSyncAs("Fax");
        faxPhoneMocVO.setMocType(Constants.MOC_FAX);   // hardcoded to "Fax" type

        individualVO.setMOC(faxPhoneMocVO);
      }

      // set otherPhone
      String otherPhone = (String)contactForm.get("otherPhone");
      if (otherPhone != null && (! otherPhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO otherPhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String otherPhoneExt = (String)contactForm.get("otherPhoneExt");
        if (otherPhoneExt != null && ! otherPhoneExt.equals(""))
        {
          otherPhone = otherPhone + "EXT" + otherPhoneExt;
        }
        otherPhoneMocVO.setContent(otherPhone);
        otherPhoneMocVO.setSyncAs("Other");
        otherPhoneMocVO.setMocType(Constants.MOC_OTHER);   // hardcoded to "Phone" type

        individualVO.setMOC(otherPhoneMocVO);
      }

      // set mainPhone
      String mainPhone = (String)contactForm.get("mainPhone");
      if (mainPhone != null && (! mainPhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO mainPhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String mainPhoneExt = (String)contactForm.get("mainPhoneExt");
        if (mainPhoneExt != null && ! mainPhoneExt.equals(""))
        {
          mainPhone = mainPhone + "EXT" + mainPhoneExt;
        }
        mainPhoneMocVO.setContent(mainPhone);
        mainPhoneMocVO.setSyncAs("Main");
        mainPhoneMocVO.setMocType(Constants.MOC_MAIN);   // hardcoded to "Phone" type

        individualVO.setMOC(mainPhoneMocVO);
      }

      // set pagerPhone
      String pagerPhone = (String)contactForm.get("pagerPhone");
      if (pagerPhone != null && (! pagerPhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO pagerPhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String pagerPhoneExt = (String)contactForm.get("pagerPhoneExt");
        if (pagerPhoneExt != null && ! pagerPhoneExt.equals(""))
        {
          pagerPhone = pagerPhone + "EXT" + pagerPhoneExt;
        }
        pagerPhoneMocVO.setContent(pagerPhone);
        pagerPhoneMocVO.setSyncAs("Pager");
        pagerPhoneMocVO.setMocType(Constants.MOC_PAGER);   // hardcoded to "Phone" type

        individualVO.setMOC(pagerPhoneMocVO);
      }

      // set mobilePhone
      String mobilePhone = (String)contactForm.get("mobilePhone");
      if (mobilePhone != null && (! mobilePhone.equals("")))
      {
        // create new MocVO object
        MethodOfContactVO mobilePhoneMocVO = new MethodOfContactVO();
       
        // set properties
        String mobilePhoneExt = (String)contactForm.get("mobilePhoneExt");
        if (mobilePhoneExt != null && ! mobilePhoneExt.equals(""))
        {
          mobilePhone = mobilePhone + "EXT" + mobilePhoneExt;
        }
        mobilePhoneMocVO.setContent(mobilePhone);
        mobilePhoneMocVO.setSyncAs("Mobile");
        mobilePhoneMocVO.setMocType(Constants.MOC_MOBILE);   // hardcoded to "Mobile" type

        individualVO.setMOC(mobilePhoneMocVO);
      }

      // get notes field
      String notes = (String)contactForm.get("notes");
      boolean addNote = (notes != null && notes.length() > 0) ? true : false;

      // first, we need to get the entityID based on the CompanyName
      // passed into the form. If the entity name doesn't match something
      // in the database, then set a flag to create a new entity.
      int companyID = 0;
      int finalEntityID = 0;
      boolean createNewEntity = false;
      if (companyName != null && (! companyName.equals("")))
      {
        companyID = sfremote.findCompanyNameMatch(companyName, individualID);

        if (companyID == 0)
        {
          createNewEntity = true;
        }else{
          finalEntityID = companyID;
        }
      }   // end  if (companyName != null && (! companyName.equals("")))

      // now that we've got all the Individual's info set
      // up properly in the appropriate VO objects, let's
      // create an Entity if necessary
      if (createNewEntity)
      {
        // we must have set the createNewEntity flag to true
        // above, when we checked for a matching entity name
        // in the database, and didn't find one.
        EntityVO newEntity = new EntityVO();
        newEntity.setContactType(1);    // contact type 1 = Entity
        newEntity.setName(companyName);

        // set the new Entity's primary Address equal to the
        // same data for the new Individual
        newEntity.setPrimaryAddress(primaryAddress);
       
        Vector indivMOCs = individualVO.getMOC();
        Iterator iter = indivMOCs.iterator();
        while (iter.hasNext())
        {
          // set the new Entity's methods of contacts equal
          // to the same data for the new Individual
          MethodOfContactVO tmpVO = (MethodOfContactVO)iter.next();
          newEntity.setMOC(tmpVO);
        }

        int newEntityID = remote.createEntity(newEntity, individualID);

        // 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 entityIDs = new ArrayList();
          try
          {
            entityIDs.add(new Integer(newEntityID));
          }catch(NumberFormatException nfe){
            // don't need to do anything, because we obviously didn't add an entity successfully.
          }
          sfremote.markRecordsPrivate(14, entityIDs);
        }

        finalEntityID = newEntityID;
        individualVO.setIsPrimaryContact("Yes");
      }
     
      // create the individual record via the ContactFacade
      individualVO.setEntityID(finalEntityID);
      int newIndividualID = remote.createIndividual(individualVO, individualID);
     
      if (newIndividualID != 0)
      {
        if (addNote)
        {
          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 title = "";
          if (notes.length() > 22)
          {
            title = notes.substring(0, 22) + "...";
          }else{
            title = notes;
          }
         
          noteVO.setTitle(title);
          noteVO.setDetail(notes);
          noteVO.setPriority(NoteVO.NP_MEDIUM);
          noteVO.setCreatedBy(individualID);
          noteVO.setOwner(individualID);
          noteVO.setRelateEntity(finalEntityID);
          noteVO.setRelateIndividual(newIndividualID);
         
          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();
          }
        }   // end if (addNote)

       
        // TODO: 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 individualIDs = new ArrayList();
          try
          {
            individualIDs.add(new Integer(newIndividualID));
          }catch(NumberFormatException nfe){
            // don't need to do anything, because we obviously didn't add an entity successfully.
          }
          sfremote.markRecordsPrivate(15, individualIDs);
        }

        // 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");
       
        // now print the new record's ID to the browser
        writer.print(newIndividualID);
      }else{
        writer.print("FAIL: Could not create Contact record.");
        return(null);
      }
    }catch(Exception e){
      System.out.println("[SyncContactAdd] Exception thrown in execute(): " + e);
      //e.printStackTrace();
    }

    // encode the output according to the CompanionLink specs
    String formattedOutput = output.toString();

    // print the output to STDOUT (http response)
    writer.print(formattedOutput);
   
    // we're not forwarding to a JSP, so return null
    return(null);
  }   // end execute()
View Full Code Here

              System.out.println("FAILURE!");
              JenaUtil.getModelFromGraph(currentGraph).write(
                  System.out);
              ModelFactory.createModelForGraph(retrievedGraph)
                  .write(System.out);
              PrintWriter pout = new PrintWriter(System.out);
              new MoleculeDiffImpl(
                  new ReferenceGroundedDecompositionImpl(
                      new ModelReferencingDecompositionImpl(
                          currentGraph)),
                          new ReferenceGroundedDecompositionImpl(
                              new ModelReferencingDecompositionImpl(
                                  retrievedGraph)))
                  .print(pout);
              pout.flush();
              retrievedGraph = store.getGraphOverTime(
                  Collections.singleton(source)).getGraph(
                  new Date());
              System.out.println("on second attempt: "+retrievedGraph.equals(currentGraph));
              System.exit(1);
View Full Code Here

  public static void main(String[] args) throws Exception {
    //Reader fileReader = new InputStreamReader(MultiReader.class.getResourceAsStream("failing-case-20061108.txt"));
    Reader fileReader =  new FileReader("failing-case.txt");
    BufferedReader in = new BufferedReader(fileReader);
    int modelNumber = 0;
    PrintWriter currentOut = null;
    for (String line = in.readLine(); line != null; line = in.readLine()) {
      if (line.equals("<rdf:RDF")) {
        currentOut = new PrintWriter(new OutputStreamWriter(getProcessor(modelNumber++).getOutputStream()));
      }
      if (line.equals("</rdf:RDF>")) {
        currentOut.println(line);
        currentOut.close();
        currentOut = null;
      }
      if (currentOut != null) {
        currentOut.println(line);
      }
    }

  }
View Full Code Here

    public final static String getStackTrace(Throwable ex) {
        String result = "";
        if (ex != null) {
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                pw.close();
                sw.close();
                result = sw.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
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.