List of usage examples for java.lang IllegalArgumentException printStackTrace
public void printStackTrace()
From source file:com.zimbra.cs.account.ProvUtil.java
private void doSearchCalendarResources(String[] args) throws ServiceException { boolean verbose = false; int i = 1;/*from w w w . j a v a 2 s. c om*/ if (args.length < i + 1) { usage(); return; } if (args[i].equals("-v")) { verbose = true; i++; } if (args.length < i + 1) { usage(); return; } Domain d = lookupDomain(args[i++]); if ((args.length - i) % 3 != 0) { usage(); return; } EntrySearchFilter.Multi multi = new EntrySearchFilter.Multi(false, EntrySearchFilter.AndOr.and); for (; i < args.length;) { String attr = args[i++]; String op = args[i++]; String value = args[i++]; try { EntrySearchFilter.Single single = new EntrySearchFilter.Single(false, attr, op, value); multi.add(single); } catch (IllegalArgumentException e) { printError("Bad search op in: " + attr + " " + op + " '" + value + "'"); e.printStackTrace(); usage(); return; } } EntrySearchFilter filter = new EntrySearchFilter(multi); String filterStr = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter); SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(); searchOpts.setDomain(d); searchOpts.setTypes(ObjectType.resources); searchOpts.setSortOpt(SortOpt.SORT_ASCENDING); searchOpts.setFilterString(FilterId.ADMIN_SEARCH, filterStr); List<NamedEntry> resources = prov.searchDirectory(searchOpts); // List<NamedEntry> resources = prov.searchCalendarResources(d, filter, null, null, true); for (NamedEntry entry : resources) { CalendarResource resource = (CalendarResource) entry; if (verbose) { dumpCalendarResource(resource, true, null); } else { console.println(resource.getName()); } } }
From source file:i5.las2peer.services.mobsos.SurveyService.java
/** * TODO: write documentation/* w ww .ja va2s . c o m*/ * Updates a survey with a given id. The respective survey may only be deleted, if the active agent is the survey's owner. * * @param id * @return */ @PUT @Consumes(MediaType.APPLICATION_JSON) @Path("surveys/{id}") @Summary("update given survey.") @Notes("Requires authentication. Use parent resource to retrieve list of existing surveys.") @ApiResponses(value = { @ApiResponse(code = 200, message = "Survey updated successfully."), @ApiResponse(code = 400, message = "Survey data invalid."), @ApiResponse(code = 401, message = "Survey may only be updated by its owner."), @ApiResponse(code = 404, message = "Survey does not exist.") }) public HttpResponse updateSurvey(@PathParam("id") int id, @ContentParam String content) { if (getActiveAgent().getId() == getActiveNode().getAnonymous().getId()) { HttpResponse noauth = new HttpResponse("Please authenticate to update survey!"); noauth.setStatus(401); } String onAction = "updating survey " + id; try { Connection c = null; PreparedStatement s = null; ResultSet rs = null; // +++ dsi try { int exown; // survey may only be updated if survey exists and active agent is owner exown = checkExistenceOwnership(id, 0); // check if survey exists; if not, return 404. if (exown == -1) { HttpResponse result = new HttpResponse("Survey " + id + " does not exist."); result.setStatus(404); return result; } // if survey exists, check if active agent is owner. if not, return 401. else if (exown == 0) { HttpResponse result = new HttpResponse("Survey " + id + " may only be deleted by its owner."); result.setStatus(401); return result; } // if survey exists and active agent is owner, proceed. JSONObject o; // parse and validate content. If invalid, return 400 (bad request) try { o = parseSurvey(content); } catch (IllegalArgumentException e) { HttpResponse result = new HttpResponse("Invalid survey data! " + e.getMessage()); result.setStatus(400); return result; } c = dataSource.getConnection(); s = c.prepareStatement("update " + jdbcSchema + ".survey set organization=?, logo=?, name=?, description=?, resource=?, start=?, end=?, lang=? where id = ?"); s.setString(1, (String) o.get("organization")); s.setString(2, (String) o.get("logo")); s.setString(3, (String) o.get("name")); s.setString(4, (String) o.get("description")); s.setString(5, (String) o.get("resource")); s.setTimestamp(6, new Timestamp(DatatypeConverter.parseDateTime((String) o.get("start")).getTimeInMillis())); s.setTimestamp(7, new Timestamp(DatatypeConverter.parseDateTime((String) o.get("end")).getTimeInMillis())); s.setString(8, (String) o.get("lang")); s.setInt(9, id); s.executeUpdate(); HttpResponse result = new HttpResponse("Survey " + id + " updated successfully."); result.setStatus(200); return result; } catch (Exception e) { e.printStackTrace(); return internalError(onAction); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { e.printStackTrace(); return internalError(onAction); } try { if (s != null) s.close(); } catch (Exception e) { e.printStackTrace(); return internalError(onAction); } try { if (c != null) c.close(); } catch (Exception e) { e.printStackTrace(); return internalError(onAction); } } // --- dsi } catch (Exception e) { e.printStackTrace(); return internalError(onAction); } }
From source file:org.fcrepo.oai.service.OAIProviderService.java
public JAXBElement<OAIPMHtype> listRecords(Session session, UriInfo uriInfo, String metadataPrefix, String from, String until, String set, int offset) throws RepositoryException { final HttpIdentifierTranslator translator = new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);/*from w w w . j a v a 2 s. c om*/ if (metadataPrefix == null) { return error(VerbType.LIST_RECORDS, null, null, OAIPMHerrorcodeType.BAD_ARGUMENT, "metadataprefix is invalid"); } final MetadataFormat mdf = metadataFormats.get(metadataPrefix); if (mdf == null) { return error(VerbType.LIST_RECORDS, null, metadataPrefix, OAIPMHerrorcodeType.CANNOT_DISSEMINATE_FORMAT, "Unavailable metadata format"); } DateTime fromDateTime = null; DateTime untilDateTime = null; try { fromDateTime = (from != null && !from.isEmpty()) ? dateFormat.parseDateTime(from) : null; untilDateTime = (until != null && !until.isEmpty()) ? dateFormat.parseDateTime(until) : null; } catch (IllegalArgumentException e) { return error(VerbType.LIST_RECORDS, null, metadataPrefix, OAIPMHerrorcodeType.BAD_ARGUMENT, e.getMessage()); } final StringBuilder sparql = new StringBuilder("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> ") .append("SELECT ?sub ?obj WHERE { ").append("?sub <").append(mdf.getPropertyName()) .append("> ?obj . "); final List<String> filters = new ArrayList<>(); if (fromDateTime != null || untilDateTime != null) { sparql.append("?sub <").append(RdfLexicon.LAST_MODIFIED_DATE).append("> ?date . "); if (fromDateTime != null) { filters.add("?date >='" + from + "'^^xsd:dateTime "); } if (untilDateTime != null) { filters.add("?date <='" + until + "'^^xsd:dateTime "); } } if (set != null && !set.isEmpty()) { if (!setsEnabled) { return error(VerbType.LIST_RECORDS, null, metadataPrefix, OAIPMHerrorcodeType.NO_SET_HIERARCHY, "Sets are not enabled"); } sparql.append("?sub <").append(propertyIsPartOfSet).append("> ?set . "); filters.add("?set = '" + set + "'"); } int filterCount = 0; for (String filter : filters) { if (filterCount++ == 0) { sparql.append("FILTER ("); } sparql.append(filter).append(filterCount == filters.size() ? ")" : " && "); } sparql.append("}").append(" OFFSET ").append(offset).append(" LIMIT ").append(maxListSize); try { final JQLConverter jql = new JQLConverter(session, translator, sparql.toString()); final ResultSet result = jql.execute(); final OAIPMHtype oai = oaiFactory.createOAIPMHtype(); final ListRecordsType records = oaiFactory.createListRecordsType(); if (!result.hasNext()) { return error(VerbType.LIST_RECORDS, null, metadataPrefix, OAIPMHerrorcodeType.NO_RECORDS_MATCH, "No record found"); } while (result.hasNext()) { // check if the records exists final RecordType record = oaiFactory.createRecordType(); final HeaderType h = oaiFactory.createHeaderType(); final QuerySolution solution = result.next(); final Resource subjectUri = solution.get("sub").asResource(); final Resource oaiRecordUri = solution.get("obj").asResource(); if (!this.datastreamService.exists(session, translator.getPathFromSubject(oaiRecordUri))) { continue; } h.setIdentifier(subjectUri.getURI()); final FedoraObject obj = this.objectService.getObject(session, translator.getPathFromSubject(subjectUri)); h.setDatestamp(dateFormat.print(obj.getLastModifiedDate().getTime())); // get set names this object is part of final Model objModel = obj.getPropertiesDataset(translator).getDefaultModel(); final StmtIterator setNames = objModel.listStatements(translator.getSubject(obj.getPath()), objModel.createProperty(propertyIsPartOfSet), (RDFNode) null); while (setNames.hasNext()) { final FedoraObject setObject = this.objectService.getObject(session, setsRootPath + "/" + setNames.next().getObject().asLiteral().getString()); final Model setObjectModel = setObject.getPropertiesDataset(translator).getDefaultModel(); final StmtIterator setSpec = setObjectModel.listStatements( translator.getSubject(setObject.getPath()), objModel.createProperty(propertyHasSetSpec), (RDFNode) null); if (setSpec.hasNext()) { h.getSetSpec().add(setSpec.next().getObject().asLiteral().getString()); } } // get the metadata record from fcrepo final MetadataType md = oaiFactory.createMetadataType(); final Datastream mdDs = this.datastreamService.getDatastream(session, translator.getPathFromSubject(oaiRecordUri)); try { String content = IOUtils.toString(mdDs.getContent()); md.setAny(new JAXBElement<String>(new QName(mdf.getPrefix()), String.class, content)); } catch (IOException e) { throw new RepositoryException(e); } finally { IOUtils.closeQuietly(mdDs.getContent()); } record.setMetadata(md); record.setHeader(h); records.getRecord().add(record); } final RequestType req = oaiFactory.createRequestType(); if (records.getRecord().size() == maxListSize) { req.setResumptionToken(encodeResumptionToken(VerbType.LIST_RECORDS.value(), metadataPrefix, from, until, set, offset + maxListSize)); } req.setVerb(VerbType.LIST_RECORDS); req.setMetadataPrefix(metadataPrefix); oai.setRequest(req); oai.setListRecords(records); return oaiFactory.createOAIPMH(oai); } catch (Exception e) { e.printStackTrace(); throw new RepositoryException(e); } }
From source file:com.processing.core.PApplet.java
/** * Call a method in the current class based on its name. * <p/>/* w w w. ja va 2 s . c om*/ * Note that the function being called must be public. Inside the PDE, * 'public' is automatically added, but when used without the preprocessor, * (like from Eclipse) you'll have to do it yourself. */ public void method(String name) { try { Method method = getClass().getMethod(name, new Class[] {}); method.invoke(this, new Object[] {}); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.getTargetException().printStackTrace(); } catch (NoSuchMethodException nsme) { System.err .println("There is no public " + name + "() method " + "in the class " + getClass().getName()); } catch (Exception e) { e.printStackTrace(); } }
From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java
/** * In this function (prescribed by Android), we collect all information * about the new vehicle and input it into a vehicle object. * This is then saved./* w ww . j av a2s . com*/ * * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addinventory); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); uController = new UserController(getApplicationContext()); // TODO: Needs to smell more MVCish //vehicleImage = (ImageButton) findViewById(R.id.vehicleImage); gallery = (LinearLayout) findViewById(R.id.addinventorygallery); delete = (Button) findViewById(R.id.delete); vehicleName = (EditText) findViewById(R.id.vehicleField); vehicleQuantity = (EditText) findViewById(R.id.quantityField); vehicleComments = (EditText) findViewById(R.id.commentsField); vehiclePublic = (Switch) findViewById(R.id.ispublic); done = (Button) findViewById(R.id.button); location = (EditText) findViewById(R.id.locationField); vehicle = new Vehicle(); //Assign and display the current location geolocation = new Geolocation(); try { current = geolocation.getCurrentLocation(getApplicationContext(), this); location.setText(current.getPostalCode()); } catch (IllegalArgumentException e) { location.setText("Geolocation cannot be determined."); } /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ categorySpinner = (Spinner) findViewById(R.id.categorySpinner); categorySpinner.setAdapter(new ArrayAdapter<VehicleCategory>(this, android.R.layout.simple_spinner_dropdown_item, VehicleCategory.values())); categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleCategory = (VehicleCategory) categorySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ qualitySpinner = (Spinner) findViewById(R.id.qualitySpinner); qualitySpinner.setAdapter(new ArrayAdapter<VehicleQuality>(this, android.R.layout.simple_spinner_dropdown_item, VehicleQuality.values())); qualitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleQuality = (VehicleQuality) qualitySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); final boolean loadVehicle = getIntent().hasExtra("vehiclePosition"); Vehicle loaded; if (loadVehicle) { position = getIntent().getIntExtra("vehiclePosition", 0); loaded = UserSingleton.getCurrentUser().getInventory().getList().get(position); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first vehicle.setPhotoIds(loaded.getPhotoIds()); vehicleName.setText(loaded.getName()); vehicleQuantity.setText(loaded.getQuantity().toString()); vehicleComments.setText(loaded.getComments()); vehiclePublic.setChecked(loaded.getPublic()); qualitySpinner.setSelection(loaded.getQuality().getPosition()); categorySpinner.setSelection(loaded.getCategory().getPosition()); // TODO: Fix null error issue //location.setText(loaded.getLocation().getPostalCode()); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (UniqueID uid : vehicle.getPhotoIds()) { photos.add(ldm.loadPhoto(uid.getID())); } for (Photo photo : photos) { ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } //default the photo to a new photo if we are not loading a vehicle else { // TODO: Default photo? Here or set in Vehicle? Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); vehicle.deletePhotoArrayList(getApplicationContext()); } LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } /** * This onClick listener implements the function that clicking on the default * image box at the top of the vehicle page will open the camera and allow the * user to take a photo which will be saved directly to the vehicle object */ gallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakePictureIntent(); } }); /** * This onClick listener occurs when someone clicks delete. This will delete the photo * that is initialized in the view. */ delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //vehicle.setPhoto(new Photo(getApplicationContext())); //vehicleImage.setBackground(new BitmapDrawable(getResources(), vehicle.getPhoto().getImage())); vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (Photo photo1 : photos) { ldm.deletePhoto(photo1.getUid().getID()); } photos.clear(); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first if (vehicle.getPhotoIds().size() > 0 && UserSingleton.getDownloadPhotos()) { gallery.removeAllViews(); } for (UniqueID uid : vehicle.getPhotoIds()) { if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } }); /** * This onClick listener occurs after done button is clicked. This would save * the object to inventory -- which then makes it appear in the inventory tab. * * Taken from Oracle Documentation - we found we were required to catch the * possibility that a number might be the wrong format, or not even a number * at all. Accessed November 3, 2015. * * @see <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-">Oracle</a> */ done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // vehicle.setPhoto(vehicleImage); Geolocation geolocation1 = new Geolocation(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); if (vehicleName.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Please enter name", Toast.LENGTH_SHORT).show(); return; } if (vehicleQuantity.getText().toString().equals("0") || vehicleQuantity.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Quantity cannot be 0", Toast.LENGTH_SHORT).show(); return; } vehicle.setName(vehicleName.getText().toString()); vehicle.setCategory(vehicleCategory); vehicle.setQuality(vehicleQuality); vehicle.setLocation(geolocation1.setSpecificLocation(getApplicationContext(), AddInventoryActivity.this, location.getText().toString())); //http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int- //Nov. 3/ 2015 //the error should never occur as we force the user to input a numeric value, but //we are required to catch it anyway try { vehicle.setQuantity(Integer.parseInt(vehicleQuantity.getText().toString())); } catch (NumberFormatException e) { e.printStackTrace(); } vehicle.setComments(vehicleComments.getText().toString()); vehicle.setPublic(vehiclePublic.isChecked()); vehicle.setBelongsTo(UserSingleton.getCurrentUser().getUserName()); for (Photo photo : photos) { vehicle.addPhoto(photo.getUid()); ldm.savePhoto(photo); } //add the vehicle to our current user. if (loadVehicle) { //UserSingleton.getCurrentUser().getInventory().getList().add(position, vehicle); uController.getUserInventoryItems().add(position, vehicle); //UserSingleton.getCurrentUser().getInventory().getList().remove(position+1); uController.getUserInventoryItems().remove(position + 1); } else { //UserSingleton.getCurrentUser().addItem(vehicle); uController.getCurrentUser().addItem(vehicle); } //save the user to ensure all changes are updated uController.saveCurrentUser(); Gson gson = new Gson(); String s = gson.toJson(vehicle); Log.i("SizeOfCar", Integer.toString(s.length())); /* //dont start a new activity if we are editing a vehicle if(!loadVehicle) { Intent intent = new Intent(AddInventoryActivity.this, MainMenu.class); startActivity(intent); }*/ finish(); } }); gallery.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } return true; } }); }
From source file:cn.jcenterhome.web.action.CpAction.java
public ActionForward cp_import(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal"); Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig"); if (!Common.checkPerm(request, response, "allowblog")) { MessageVO msgVO = Common.ckSpaceLog(request); if (msgVO != null) { return showMessage(request, response, msgVO); }/*from www . j ava 2s.c o m*/ return showMessage(request, response, "no_privilege"); } if (!cpService.checkRealName(request, "blog")) { return showMessage(request, response, "no_privilege_realname"); } if (!cpService.checkVideoPhoto(request, response, "blog")) { return showMessage(request, response, "no_privilege_videophoto"); } switch (cpService.checkNewUser(request, response)) { case 1: break; case 2: return showMessage(request, response, "no_privilege_newusertime", "", 1, String.valueOf(sConfig.get("newusertime"))); case 3: return showMessage(request, response, "no_privilege_avatar"); case 4: return showMessage(request, response, "no_privilege_friendnum", "", 1, String.valueOf(sConfig.get("need_friendnum"))); case 5: return showMessage(request, response, "no_privilege_email"); } int waitTime = Common.checkInterval(request, response, "post"); if (waitTime > 0) { return showMessage(request, response, "operating_too_fast", "", 1, String.valueOf(waitTime)); } try { String siteUrl = Common.getSiteUrl(request); File userFile = new File(JavaCenterHome.jchRoot + "./data/temp/" + sGlobal.get("supe_uid") + ".data"); if (submitCheck(request, "importsubmit")) { Map reward = Common.getReward("blogimport", false, 0, "", true, request, response); Map space = (Map) request.getAttribute("space"); int spaceExperience = (Integer) space.get("experience"); int spaceCredit = (Integer) space.get("credit"); int rewardExperience = (Integer) reward.get("experience"); int rewardCredit = (Integer) reward.get("credit"); if (spaceExperience < rewardExperience) { return showMessage(request, response, "experience_inadequate", "", 1, new String[] { String.valueOf(spaceExperience), String.valueOf(rewardExperience) }); } if (spaceCredit < rewardCredit) { return showMessage(request, response, "integral_inadequate", "", 1, new String[] { String.valueOf(spaceCredit), String.valueOf(rewardCredit) }); } String url = request.getParameter("url").trim(); Map urls = cpService.parseUrl(url); if (Common.empty(url) || urls.isEmpty()) { return showMessage(request, response, "url_is_not_correct"); } XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL(new URL(url)); XmlRpcClient client = new XmlRpcClient(); client.setConfig(config); Vector params = new Vector(); params.addElement("blog"); params.addElement( Common.sHtmlSpecialChars(Common.siconv(request.getParameter("username"), "utf-8", "", ""))); params.addElement(Common.sHtmlSpecialChars(request.getParameter("password"))); params.addElement(sConfig.get("importnum")); Object[] results = (Object[]) client.execute("metaWeblog.getRecentPosts", params); if (results == null || results.length == 0) { return showMessage(request, response, "blog_import_no_data", null, 1, "<textarea name=\"tmp[]\" style=\"width:98%;\" rows=\"4\">no data</textarea>"); } HashMap last = (HashMap) results[results.length - 1]; if (last.containsKey("postid") == false) { return showMessage(request, response, "blog_import_no_data", null, 1, Common.implode(last, ",")); } PHPSerializer phpSerializer = new PHPSerializer(JavaCenterHome.JCH_CHARSET); FileHelper.writeFile(userFile, phpSerializer.serialize(results)); request.setAttribute("results", results); request.setAttribute("incount", 0); } else if (submitCheck(request, "import2submit")) { ArrayList results = null; if (userFile.exists()) { String result = FileHelper.readFile(userFile); if (Common.empty(result) == false) { PHPSerializer phpSerializer = new PHPSerializer(JavaCenterHome.JCH_CHARSET); results = ((AssocArray) phpSerializer.unserialize(result)).toArrayList(); } } String[] ids = request.getParameterValues("ids[]"); if (Common.empty(results) || Common.empty(ids)) { return showMessage(request, response, "choose_at_least_one_log", "cp.jsp?ac=import"); } int allCount = 0; int inCount = 0; ArrayList newResults = new ArrayList(); for (int i = 0, size = results.size(); i < size; i++) { int key = i; allCount += 1; Map currBlog = ((AssocArray) results.get(i)).toHashMap(); if (currBlog.get("dateCreated") instanceof Calendar) { Calendar calendar = (Calendar) currBlog.get("dateCreated"); int dateline = (int) (calendar.getTimeInMillis() / 1000); currBlog.put("dateCreated", Common.gmdate("yyyyMMdd'T'HH:mm:ss", dateline, String.valueOf(sConfig.get("timeoffset")))); } if (Common.in_array(ids, key)) { Map value = (Map) Common.sAddSlashes(currBlog); int dateline = Common.strToTime(value.get("dateCreated").toString(), String.valueOf(sConfig.get("timeoffset")), "yyyyMMdd'T'HH:mm:ss"); String subject = Common.getStr(value.get("title").toString(), 80, true, true, true, 0, 0, request, response); String message = value.containsKey("description") ? value.get("description").toString() : value.get("content").toString(); message = Common.getStr(message, 0, true, true, true, 0, 1, request, response); message = blogService.checkHtml(request, response, message); if (Common.empty(subject) || Common.empty(message)) { currBlog.put("status", "--"); currBlog.put("blogid", 0); continue; } Map blogarr = new HashMap(); blogarr.put("uid", sGlobal.get("supe_uid")); blogarr.put("username", sGlobal.get("supe_username")); blogarr.put("subject", subject); blogarr.put("pic", blogService.getMessagePic(message)); blogarr.put("dateline", dateline != 0 ? dateline : sGlobal.get("timestamp")); int blogId = dataBaseService.insertTable("blog", blogarr, true, false); Map fieldarr = new HashMap(); fieldarr.put("blogid", blogId); fieldarr.put("uid", sGlobal.get("supe_uid")); fieldarr.put("message", message); fieldarr.put("postip", Common.getOnlineIP(request)); fieldarr.put("related", ""); fieldarr.put("target_ids", ""); fieldarr.put("hotuser", ""); dataBaseService.insertTable("blogfield", fieldarr, false, false); inCount += 1; currBlog.put("status", "OK"); currBlog.put("blogid", blogId); } else { currBlog.put("status", "--"); currBlog.put("blogid", 0); } newResults.add(currBlog); } if (inCount != 0) { Common.getReward("blogimport", true, 0, "", true, request, response); userFile.delete(); } request.setAttribute("results", newResults); request.setAttribute("incount", inCount); } else if (submitCheck(request, "resubmit")) { userFile.delete(); } request.setAttribute("siteurl", siteUrl); } catch (XmlRpcException xre) { return showMessage(request, response, "blog_import_no_data", null, 1, "<textarea name=\"tmp[]\" style=\"width:98%;\" rows=\"4\">" + xre.code + ", " + xre.getMessage() + "</textarea>"); } catch (IllegalAccessException iace) { iace.printStackTrace(); } catch (IllegalArgumentException iare) { iare.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } return include(request, response, sConfig, sGlobal, "cp_import.jsp"); }