List of usage examples for java.lang String contentEquals
public boolean contentEquals(CharSequence cs)
From source file:de.intranda.goobi.plugins.utils.ModsUtils.java
/** * //from w w w . j a va 2 s. c om * @param pres * @param dsLogical * @param dsPhysical * @param eleMods * @param mappingFile * @throws IOException * @throws JDOMException */ @SuppressWarnings("unchecked") public static void parseModsSection(CSICOAIImport plugin, DocStruct dsLogical, DocStruct dsAnchor, DocStruct dsPhysical, Element eleMods, int volumeNo, String pieceDesignation) throws JDOMException, IOException { fillPersonRoleMap(); String mappingFileName = CSICOAIImport.MODS_MAPPING_FILE; Prefs prefs = plugin.getPrefs(); String suffix = plugin.getCurrentSuffix(); boolean writeAllMetadataToAnchor = false; if (dsAnchor != null && dsAnchor.getType().getName().contentEquals("MultiVolumeWork")) { writeAllMetadataToAnchor = true; } File mappingFile = new File(mappingFileName); File seriesInfoFile = new File(TEMP_DIRECTORY, seriesInfoFilename); if (seriesInfoFile.isFile()) { logger.debug("Reading data from " + seriesInfoFile.getName()); Object obj = readFile(seriesInfoFile); if (obj instanceof HashMap<?, ?>) { seriesInfo = (HashMap<String, String>) obj; } } Document doc = new Document(); Element eleNewMods = (Element) eleMods.clone(); doc.setRootElement(eleNewMods); Document mapDoc = new SAXBuilder().build(mappingFile); String seriesTitle = null; String seriesID = null; List<String> publicationYears = new ArrayList<String>(); for (Object obj : mapDoc.getRootElement().getChildren("metadata", null)) { Element eleMetadata = (Element) obj; String mdName = eleMetadata.getChildTextTrim("name", null); if ("location".equals(mdName)) { // write location info int counter = 0; List<Element> eleXpathList = eleMetadata.getChildren("xpath", null); if (eleXpathList == null || eleXpathList.isEmpty()) { continue; } String query = eleXpathList.get(0).getTextTrim(); XPath xpath = XPath.newInstance(query); xpath.addNamespace(NS_MODS); List<Element> eleValueList = xpath.selectNodes(doc); for (Element element : eleValueList) { int locationVolumeNo = getVolumeNumberFromLocation(element); if (locationVolumeNo > 0 && locationVolumeNo != volumeNo) { continue; } String shelfmarkSource = null; String physicalLocation = null; String physicalCollection = null; String localPieceDesignation = null; int localVolumeNo = -1; boolean isCurrentColume = true; Element eleShelfmarkSource = element.getChild("shelfLocator", NS_MODS); if (eleShelfmarkSource != null) { shelfmarkSource = eleShelfmarkSource.getValue(); } Element elePhysLocation = element.getChild("physicalLocation", NS_MODS); if (elePhysLocation != null) { physicalLocation = elePhysLocation.getValue(); } Element eleHoldingSimple = element.getChild("holdingSimple", NS_MODS); if (eleHoldingSimple != null) { Element eleCopyInformation = eleHoldingSimple.getChild("copyInformation", NS_MODS); if (eleCopyInformation != null) { Element elePhysicalCollection = eleCopyInformation.getChild("subLocation", NS_MODS); if (elePhysicalCollection != null) { physicalCollection = elePhysicalCollection.getValue(); } Element elePieceDesignation = eleCopyInformation.getChild("pieceDesignation", NS_MODS); if (elePieceDesignation != null) { localPieceDesignation = elePieceDesignation.getValue(); } Element eleVolumeNo = eleCopyInformation.getChild("VolumeNo", NS_MODS); if (eleVolumeNo == null) { eleVolumeNo = eleCopyInformation.getChild("VolumeLabel", NS_MODS); } if (eleVolumeNo != null) { String volumeString = eleVolumeNo.getValue().replaceAll("\\D", ""); if (volumeString != null && !volumeString.isEmpty()) { localVolumeNo = Integer.valueOf(volumeString); } } } } if (localPieceDesignation == null) { localPieceDesignation = pieceDesignation; } // if (pieceDesignation != null && localPieceDesignation.contentEquals(pieceDesignation)) { // This is either the correct volume or no volume is specified. try { String mdPrefix = ""; if (counter > 0) { mdPrefix = "copy" + volumeNumberFormat.format(counter); } if (shelfmarkSource != null) { MetadataType shelfmarkSourceType = prefs .getMetadataTypeByName(mdPrefix + "shelfmarksource"); Metadata shelfmarkSourceMetadata = new Metadata(shelfmarkSourceType); shelfmarkSourceMetadata.setValue(shelfmarkSource); dsPhysical.addMetadata(shelfmarkSourceMetadata); } if (physicalLocation != null) { MetadataType physicalLocationType = prefs .getMetadataTypeByName(mdPrefix + "physicalLocation"); Metadata physicalLocationMetadata = new Metadata(physicalLocationType); physicalLocationMetadata.setValue(physicalLocation); dsPhysical.addMetadata(physicalLocationMetadata); } if (physicalCollection != null) { MetadataType physicalCollectionType = prefs .getMetadataTypeByName(mdPrefix + "physicalCollection"); Metadata physicalCollectionMetadata = new Metadata(physicalCollectionType); physicalCollectionMetadata.setValue(physicalCollection); dsPhysical.addMetadata(physicalCollectionMetadata); } if (localPieceDesignation != null) { MetadataType pieceDesignationType = prefs .getMetadataTypeByName(mdPrefix + "pieceDesignation"); Metadata pieceDesignationMetadata = new Metadata(pieceDesignationType); pieceDesignationMetadata.setValue(localPieceDesignation); dsPhysical.addMetadata(pieceDesignationMetadata); } if (counter < 10) { counter++; } } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } // } } continue; } MetadataType mdType = prefs.getMetadataTypeByName(mdName); if (mdType != null) { List<Element> eleXpathList = eleMetadata.getChildren("xpath", null); if (mdType.getIsPerson()) { // Persons for (Element eleXpath : eleXpathList) { String query = eleXpath.getTextTrim(); // logger.debug("XPath: " + query); XPath xpath = XPath.newInstance(query); xpath.addNamespace(NS_MODS); // Element eleValue = (Element) xpath.selectSingleNode(doc); List<Element> eleValueList = xpath.selectNodes(doc); if (eleValueList != null) { for (Element eleValue : eleValueList) { String name = ""; String firstName = ""; String lastName = ""; String termsOfAddress = ""; String roleTerm = ""; String typeName = ""; for (Object o : eleValue.getChildren()) { Element eleNamePart = (Element) o; if (eleNamePart.getName().contentEquals("role")) { Element eleRoleTerm = eleNamePart.getChild("roleTerm", null); if (eleRoleTerm != null) { roleTerm = eleRoleTerm.getValue(); } } else { String type = eleNamePart.getAttributeValue("type"); if (type == null || type.isEmpty()) { // no type name = eleNamePart.getValue(); } else if (type.contentEquals("date")) { // do nothing? } else if (type.contentEquals("termsOfAddress")) { termsOfAddress = eleNamePart.getValue(); } else if (type.contentEquals("given")) { firstName = eleNamePart.getValue(); } else if (type.contentEquals("family")) { lastName = eleNamePart.getValue(); } } } // set metadata type to role if (roleTerm != null && !roleTerm.isEmpty()) { roleTerm = roleTerm.replaceAll("\\.", ""); typeName = personRoleMap.get(roleTerm.toLowerCase()); if (typeName == null) { String[] parts = roleTerm.split(" "); if (parts != null && parts.length > 0) { typeName = personRoleMap.get(parts[0].toLowerCase()); } if (typeName == null) { typeName = mdName; } } } else { // with no role specified, assume it is an author typeName = "Author"; } mdType = prefs.getMetadataTypeByName(typeName); if (name.contains(",")) { String[] nameSplit = name.split("[,]"); if (nameSplit.length > 0 && StringUtils.isEmpty(lastName)) { lastName = nameSplit[0].trim(); } if (nameSplit.length > 1 && StringUtils.isEmpty(firstName)) { for (int i = 1; i < nameSplit.length; i++) { firstName += nameSplit[i].trim() + ", "; } firstName = firstName.substring(0, firstName.length() - 2); } } else { lastName = name; } if (StringUtils.isNotEmpty(lastName)) { try { Person person = new Person(mdType); person.setFirstname(firstName); person.setLastname(lastName); person.setRole(mdType.getName()); if (eleMetadata.getAttribute("logical") != null && eleMetadata .getAttributeValue("logical").equalsIgnoreCase("true")) { dsLogical.addPerson(person); if (writeAllMetadataToAnchor) { dsAnchor.addPerson(person); } } } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } } } } } else { // Regular metadata List<String> values = new ArrayList<String>(); String separator = " "; if (eleMetadata.getAttribute("separator") != null) { separator = eleMetadata.getAttributeValue("separator"); } for (Element eleXpath : eleXpathList) { String query = eleXpath.getTextTrim(); // logger.debug("XPath: " + query); XPath xpath = XPath.newInstance(query); xpath.addNamespace(NS_MODS); List eleValueList = xpath.selectNodes(doc); if (eleValueList != null) { if (mdName.contentEquals("Taxonomy")) { for (Object objValue : eleValueList) { if (objValue instanceof Element) { Element eleValue = (Element) objValue; List<Element> subjectChildren = eleValue.getChildren(); String value = ""; for (Element element : subjectChildren) { if (taxonomyFieldsList.contains(element.getName().toLowerCase())) { List<Element> subElements = element.getChildren(); if (subElements != null && !subElements.isEmpty()) { String subValue = ""; for (Element subElement : subElements) { if (subElement.getValue() != null && !subElement.getValue().trim().isEmpty()) { subValue = subValue + " " + subElement.getValue(); } } value = value + separator + subValue.trim(); } else if (element.getValue() != null && !element.getValue().trim().isEmpty()) { value = value + separator + element.getValue(); } } } if (value.length() > separator.length()) { value = value.substring(separator.length()).trim(); values.add(value); } } } } else { int count = 0; for (Object objValue : eleValueList) { String value = null; if (objValue instanceof Element) { Element eleValue = (Element) objValue; logger.debug("mdType: " + mdType.getName() + "; Value: " + eleValue.getTextTrim()); value = getElementValue(eleValue, ", "); // value = eleValue.getTextTrim(); } else if (objValue instanceof Attribute) { Attribute atrValue = (Attribute) objValue; logger.debug( "mdType: " + mdType.getName() + "; Value: " + atrValue.getValue()); value = atrValue.getValue(); } boolean mergeXPaths = mergeXPaths(eleMetadata); if (value != null && (values.size() <= count || !mergeXPaths)) { values.add(value); } else if (value != null) { value = values.get(count) + separator + value; values.set(count, value); } count++; } } } } for (String value : values) { if (mdType.getName().contentEquals("CurrentNoSorting")) { value = correctCurrentNoSorting(value); } else if (mdType.getName().contentEquals("CurrentNo")) { value = formatVolumeString(value, PREFIX_SERIES); } else if (!writeAllMetadataToAnchor && mdType.getName().contentEquals("TitleDocParallel")) { seriesTitle = value; } // // Add singleDigCollection to series also // if (!writeAllMetadataToAnchor && anchorMetadataList.contains(mdType.getName()) && dsAnchor != null) { // // if (mdType.getName().contentEquals("singleDigCollection") && dsSeries != null) { // try { // if (value.length() > 0) { // Metadata metadata = new Metadata(mdType); // metadata.setValue(value); // logger.debug("Found metadata: " + metadata.getType().getName()); // if (eleMetadata.getAttribute("logical") != null // && eleMetadata.getAttributeValue("logical").equalsIgnoreCase("true")) { // logger.debug("Added metadata \"" + metadata.getValue() + "\" to logical structure"); // dsAnchor.addMetadata(metadata); // } // } // } catch (MetadataTypeNotAllowedException e) { // logger.warn(e.getMessage()); // } // } try { if (value.length() > 0) { Metadata metadata = new Metadata(mdType); metadata.setValue(value); // logger.debug("Found metadata: " + metadata.getType().getName()); if (eleMetadata.getAttribute("logical") != null && eleMetadata.getAttributeValue("logical").equalsIgnoreCase("true")) { // logger.debug("Added metadata \"" + metadata.getValue() + "\" to logical structure"); if (mdName.contentEquals("PublicationStart") || mdName.contentEquals("PublicationEnd")) { publicationYears.add(value); continue; } if (mdName.contentEquals("TitleDocMain")) { if (suffix != null && !suffix.isEmpty() && (plugin.addVolumeNoToTitle || !writeAllMetadataToAnchor)) { if (plugin.useSquareBracketsForVolume) { metadata.setValue(value + " [" + suffix + "]"); } else { metadata.setValue(value + " (" + formatVolumeString(suffix, PREFIX_VOLUME) + ")"); } } try { dsLogical.addMetadata(metadata); seriesTitle = value; } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } else if (mdName.contentEquals("CatalogIDDigital")) { if (suffix != null && !suffix.isEmpty()) { metadata.setValue(value + "_" + suffix); if (writeAllMetadataToAnchor) { seriesID = value; } } try { dsLogical.addMetadata(metadata); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } else { try { dsLogical.addMetadata(metadata); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } try { if (writeAllMetadataToAnchor && !volumeExclusiveMetadataList .contains(metadata.getType().getName())) { dsAnchor.addMetadata(metadata); } } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } } if (eleMetadata.getAttribute("physical") != null && eleMetadata.getAttributeValue("physical").equalsIgnoreCase("true")) { // logger.debug("Added metadata \"" + metadata.getValue() + "\" to physical structure"); dsPhysical.addMetadata(metadata); } } } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } } } else { logger.warn("Metadata '" + mdName + "' is not defined in the ruleset."); } } //construct PublicationYear from Start and Enddate if necessary List<? extends Metadata> mdPublicationList = dsLogical .getAllMetadataByType(prefs.getMetadataTypeByName("PublicationYear")); if ((mdPublicationList == null || mdPublicationList.isEmpty()) && !publicationYears.isEmpty()) { Collections.sort(publicationYears); String value = publicationYears.get(0); if (publicationYears.size() > 1) { value += ("-" + publicationYears.get(publicationYears.size() - 1)); } if (value != null && !value.trim().isEmpty()) { try { Metadata mdPublicationYear = new Metadata(prefs.getMetadataTypeByName("PublicationYear")); mdPublicationYear.setValue(value); try { dsLogical.addMetadata(mdPublicationYear); } catch (MetadataTypeNotAllowedException e) { logger.error(e.getMessage()); } catch (DocStructHasNoTypeException e) { logger.error(e.getMessage()); } if (writeAllMetadataToAnchor) { try { dsAnchor.addMetadata(mdPublicationYear); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } catch (DocStructHasNoTypeException e) { logger.warn(e.getMessage()); } } } catch (MetadataTypeNotAllowedException e) { logger.error(e.getMessage()); } } } // Code to handle related works, e.g. series, but only if we are not working within a MultiVolume if (!writeAllMetadataToAnchor) { String query = "/mods:mods/mods:relatedItem[@type='series']/mods:titleInfo[@type='uniform']"; XPath xpath = XPath.newInstance(query); xpath.addNamespace(NS_MODS); List<Element> eleValueList = xpath.selectNodes(doc); List<String> values = new ArrayList<String>(); if (eleValueList == null || eleValueList.isEmpty()) { query = "/mods:mods/mods:relatedItem[@type='series']/mods:titleInfo[not(@type)]"; xpath = XPath.newInstance(query); xpath.addNamespace(NS_MODS); eleValueList = xpath.selectNodes(doc); } if (eleValueList != null && !eleValueList.isEmpty()) { for (Element eleValue : eleValueList) { if (eleValue.getText() != null && !eleValue.getText().isEmpty()) { values.add(eleValue.getTextTrim()); } List<Element> eleSubList = eleValue.getChildren(); if (eleSubList != null && !eleSubList.isEmpty()) { for (Element element : eleSubList) { if (element.getName().contentEquals("title")) { if (element.getText() != null && !element.getText().isEmpty()) { values.add(element.getTextTrim()); } } } } } String value = ""; for (String s : values) { if (StringUtils.isNotEmpty(s)) { value += " " + s; } } value = value.trim(); String[] valueParts = value.split("\\s"); seriesTitle = ""; HashMap<String, Boolean> valueMap = new HashMap<String, Boolean>(); for (int i = 0; i < valueParts.length; i++) { if (!valueMap.containsKey(valueParts[i])) { seriesTitle += " " + valueParts[i]; valueMap.put(valueParts[i], true); } } seriesTitle = seriesTitle.trim(); logger.debug("related Series = " + seriesTitle); } } if (dsAnchor != null) { if (seriesID == null) { if (seriesTitle != null) { seriesID = seriesInfo.get(seriesTitle); } if (seriesID == null) { seriesID = "CSIC" + System.currentTimeMillis(); logger.debug("Series not found. creating new one: " + seriesID); } } if (seriesTitle == null) { seriesTitle = seriesID; } // Creating metadata for series try { MetadataType titleType = prefs.getMetadataTypeByName("TitleDocMain"); MetadataType idType = prefs.getMetadataTypeByName("CatalogIDDigital"); Metadata mdTitle; mdTitle = new Metadata(titleType); Metadata mdID = new Metadata(idType); mdTitle.setValue(seriesTitle); mdID.setValue(seriesID); dsAnchor.addMetadata(mdTitle); dsAnchor.addMetadata(mdID); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.getMessage()); } } // Create CurrentNo and CurrentNoSorting if necessary if (dsAnchor != null && suffix != null && !suffix.isEmpty()) { List<? extends Metadata> mdCurrentNoList = dsLogical .getAllMetadataByType(prefs.getMetadataTypeByName("CurrentNo")); if (!writeAllMetadataToAnchor || plugin.writeCurrentNoToMultiVolume) { if ((mdCurrentNoList == null || mdCurrentNoList.isEmpty())) { // No current Number, so we create one try { String value = null; Metadata md = new Metadata(prefs.getMetadataTypeByName("CurrentNo")); if (writeAllMetadataToAnchor) { value = formatVolumeString(suffix, PREFIX_VOLUME); } else { value = formatVolumeString(suffix, PREFIX_SERIES); } md.setValue(value); dsLogical.addMetadata(md); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.toString()); } } } List<? extends Metadata> mdCurrentNoSortList = dsLogical .getAllMetadataByType(prefs.getMetadataTypeByName("CurrentNoSorting")); if (!writeAllMetadataToAnchor || plugin.writeCurrentNoSortingToMultiVolume) { if (mdCurrentNoSortList == null || mdCurrentNoSortList.isEmpty() && !writeAllMetadataToAnchor) { // No current Number, so we create one try { Metadata md = new Metadata(prefs.getMetadataTypeByName("CurrentNoSorting")); String str = suffix; if (str.contains("_")) { str = suffix.split("_")[0]; } if (str.startsWith("V")) { str = str.substring(1); } str = correctCurrentNoSorting(str); md.setValue(str); dsLogical.addMetadata(md); } catch (MetadataTypeNotAllowedException e) { logger.warn(e.toString()); } } } } // write seriesInfo to file if (seriesTitle != null && !seriesTitle.isEmpty()) { seriesInfo.put(seriesTitle, seriesID); if (seriesInfoFile.isFile()) { logger.debug("deleting old seriesInfoFile"); seriesInfoFile.delete(); } writeFile(seriesInfoFile, seriesInfo); } }
From source file:de.enlightened.peris.IntroScreen.java
private void stealTapatalkLink(final String link) { final String queryLink; if (!link.startsWith("http://")) { queryLink = "http://" + link; } else {//w ww . j a v a2 s . c om queryLink = link; } if (!getString(R.string.server_location).contentEquals("0")) { if (queryLink.contentEquals(getString(R.string.server_location))) { this.connectToServer(this.selectedServer); } else { final AlertDialog.Builder builder = new AlertDialog.Builder(IntroScreen.this); builder.setTitle("Download Peris"); builder.setCancelable(true); builder.setPositiveButton("Yep!", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { final String perisURL = "https://github.com/McNetic/peris/"; final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(perisURL)); IntroScreen.this.startActivity(intent); finish(); } }); builder.setNegativeButton("Nah.", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(final DialogInterface dialog) { finish(); } }); builder.setMessage("Do you want to download and view " + link + " using Peris, the free mobile forum reader app that " + getString(R.string.app_name) + " is based off of?"); builder.create().show(); } } else { this.selectedServer = ServerRepository.findOneByAddress(this.dbHelper.getReadableDatabase(), queryLink); if (this.selectedServer != null) { if (this.selectedServer.serverAddress != null) { this.connectToServer(this.selectedServer); return; } } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { new ServerValidationTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, link.trim()); } else { new ServerValidationTask().execute(link.trim()); } } }
From source file:com.mobshep.mobileshepherd.CSInjection.java
public void onClick(View arg0) { switch (arg0.getId()) { case (R.id.bLogin): String CheckName = username.getText().toString(); String CheckPass = password.getText().toString(); try {/*from w w w . j a v a 2 s . com*/ if (login(CheckName, CheckPass) == true) { outputKey(this, dbPass); Toast login = Toast.makeText(CSInjection.this, "Logged in!", Toast.LENGTH_LONG); login.show(); } } catch (IOException e1) { Toast error = Toast.makeText(CSInjection.this, "An error occurred!", Toast.LENGTH_LONG); error.show(); } try { if (login(CheckName, CheckPass) == false) { Toast invalid = Toast.makeText(CSInjection.this, "Invalid Credentials!", Toast.LENGTH_SHORT); invalid.show(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (CheckName.contentEquals("") || CheckPass.contentEquals("") || CheckPass.contentEquals("A3B922DF010PQSI827")) { Toast empty = Toast.makeText(CSInjection.this, "Empty Fields Detected.", Toast.LENGTH_SHORT); empty.show(); } } }
From source file:de.enlightened.peris.PerisMain.java
/** * Called when the activity is first created. *//*from ww w.j a va2 s . com*/ @SuppressLint("NewApi") @Override public final void onCreate(final Bundle savedInstanceState) { this.application = (PerisApp) getApplication(); this.application.setActive(true); this.backStackId = this.application.getBackStackId(); this.ah = this.application.getAnalyticsHelper(); if (this.application.getSession().getServer().serverIcon == null) { final int optimalIconSize = (int) this.getResources().getDimension(android.R.dimen.app_icon_size); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { new CheckForumIconTask(this.application.getSession(), optimalIconSize) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { new CheckForumIconTask(this.application.getSession(), optimalIconSize).execute(); } } this.serverAddress = this.application.getSession().getServer().serverAddress; final SharedPreferences appPreferences = getSharedPreferences("prefs", 0); this.sidebarOption = appPreferences.getBoolean("show_sidebar", true); this.screenTitle = getString(R.string.app_name); if (getString(R.string.server_location).contentEquals("0")) { this.storagePrefix = this.serverAddress + "_"; this.screenSubtitle = this.serverAddress; } else { this.screenSubtitle = this.screenTitle; } this.serverUserid = this.application.getSession().getServer().serverUserId; final String tagline = this.application.getSession().getServer().serverTagline; final SharedPreferences.Editor editor = appPreferences.edit(); if (tagline.contentEquals("null") || tagline.contentEquals("0")) { final String deviceName = android.os.Build.MODEL; final String appName = getString(R.string.app_name); final String appVersion = getString(R.string.app_version); String appColor = getString(R.string.default_color); if (this.application.getSession().getServer().serverColor.contains("#")) { appColor = this.application.getSession().getServer().serverColor; } final String standardTagline = "[color=" + appColor + "][b]Sent from my " + deviceName + " using " + appName + " v" + appVersion + ".[/b][/color]"; this.application.getSession().getServer().serverTagline = standardTagline; this.application.getSession().updateServer(); } editor.putInt(this.storagePrefix + "just_logged_in", 0); editor.commit(); if (this.serverUserid != null) { final Toast toast = Toast.makeText(PerisMain.this, "TIP: Tap on the key icon to log in to your forum account.", Toast.LENGTH_LONG); toast.show(); } final Intent intent = getIntent(); final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { this.handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { this.handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { this.handleSendMultipleImages(intent); // Handle multiple images being sent } } /*else { // Handle other intents, such as being started from the home screen }*/ this.background = this.application.getSession().getServer().serverColor; ThemeSetter.setTheme(this, this.background); super.onCreate(savedInstanceState); ThemeSetter.setActionBar(this, this.background); this.actionBar = getActionBar(); this.actionBar.setDisplayHomeAsUpEnabled(true); this.actionBar.setHomeButtonEnabled(true); this.actionBar.setTitle(this.screenTitle); this.actionBar.setSubtitle(this.screenSubtitle); //Send app analytics data this.ah.trackScreen(getClass().getSimpleName(), false); this.ah.trackEvent("server connection", "connected", "connected", false); //Send tracking data for parsed analytics from peris.json this.serverAddress = this.application.getSession().getServer().analyticsId; if (this.serverAddress != null) { this.ah.trackCustomScreen(this.serverAddress, "Peris Forum Reader v" + getString(R.string.app_version) + " for Android"); } setContentView(R.layout.main_swipe); this.mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); this.flSecondary = (FrameLayout) findViewById(R.id.main_page_frame_right); this.seperator = findViewById(R.id.main_page_seperator); //Setup forum background final String forumWallpaper = this.application.getSession().getServer().serverWallpaper; final String forumBackground = this.application.getSession().getServer().serverBackground; if (forumBackground != null && forumBackground.contains("#") && forumBackground.length() == 7) { this.mDrawerLayout.setBackgroundColor(Color.parseColor(forumBackground)); } else { this.mDrawerLayout.setBackgroundColor(Color.parseColor(getString(R.string.default_background))); } if (forumWallpaper != null && forumWallpaper.contains("http")) { final ImageView mainSwipeImageBackground = (ImageView) findViewById(R.id.main_swipe_image_background); final String imageUrl = forumWallpaper; ImageLoader.getInstance().displayImage(imageUrl, mainSwipeImageBackground); } else { findViewById(R.id.main_swipe_image_background).setVisibility(View.GONE); } this.setupSlidingDrawer(); if (this.application.getStackManager().getBackStackSize(this.backStackId) == 0) { final Bundle bundle = this.initializeNewSession(appPreferences); this.loadCategory(bundle, "NEW_SESSION", false); //application.stackManager.addToBackstack(backStackId, BackStackManager.BackStackItem.BACKSTACK_TYPE_FORUM,bundle); } else { this.recoverBackstack(); } final Bundle parms = getIntent().getExtras(); if (parms != null) { if (parms.containsKey("stealing")) { final Boolean stealing = parms.getBoolean("stealing"); if (stealing) { final String stealingLocation = parms.getString("stealing_location", "0"); final String stealingType = parms.getString("stealing_type", "0"); final boolean locationNumeric = isNumeric(stealingLocation); if (stealingType.contentEquals("forum") && locationNumeric && !stealingLocation.contentEquals("0")) { this.loadTopicItem(Category.builder().id(stealingLocation).name("External Link").build()); } if (stealingType.contentEquals("topic") && locationNumeric && !stealingLocation.contentEquals("0")) { this.loadTopicItem(Topic.builder().id(stealingLocation).title("External Link").build()); } } } } //Juice up gesture listener this.enableGestures(); }
From source file:de.enlightened.peris.PerisMain.java
private void setupSidebar() { final String customChatForum = this.application.getSession().getServer().chatForum; final String customChatThread = this.application.getSession().getServer().chatThread; if (this.serverUserid != null && ((!getString(R.string.chat_thread).contentEquals("0")) || (!customChatForum.contentEquals("0") && !customChatThread.contentEquals("0")))) { final SocialFragment sf = new SocialFragment(); sf.setOnProfileSelectedListener(this.profileSocialSelected); final Bundle bundle = new Bundle(); bundle.putString("shared_text", this.incomingText); bundle.putString("background", this.background); sf.setArguments(bundle);/*from www. j ava2s .c o m*/ final FragmentManager fragmentManager = getSupportFragmentManager(); final FragmentTransaction ftZ = fragmentManager.beginTransaction(); ftZ.replace(R.id.main_page_frame_right, sf); ftZ.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ftZ.commit(); } else if (this.serverUserid == null) { final Login login = new Login(); final FragmentManager fragmentManager = getSupportFragmentManager(); final FragmentTransaction ftZ = fragmentManager.beginTransaction(); ftZ.replace(R.id.main_page_frame_right, login); ftZ.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ftZ.commit(); } else { if (this.sidebarOption) { final ActiveList active = new ActiveList(); active.setOnProfileSelectedListener(this.profileActiveSelected); final FragmentManager fragmentManager = getSupportFragmentManager(); final FragmentTransaction ftZ = fragmentManager.beginTransaction(); ftZ.replace(R.id.main_page_frame_right, active); ftZ.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); try { ftZ.commit(); } catch (Exception ex) { if (ex.getMessage() != null) { Log.w(TAG, ex.getMessage()); } } } else { this.flSecondary.setVisibility(View.GONE); } } }
From source file:com.nuvolect.deepdive.probe.DecompileApk.java
private JSONObject unpackApk() { final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override//ww w. j ava2 s.com public void uncaughtException(Thread t, Throwable e) { LogUtil.log(LogUtil.LogType.DECOMPILE, "Uncaught exception: " + e.toString()); m_progressStream.putStream("Uncaught exception: " + t.getName()); m_progressStream.putStream("Uncaught exception: " + e.toString()); } }; m_unpack_apk_time = System.currentTimeMillis(); // Save start time for tracking m_unpackApkThread = new Thread(m_threadGroup, new Runnable() { @Override public void run() { boolean success = false; try { m_progressStream = new ProgressStream( new OmniFile(m_volumeId, m_appFolderPath + "unpack_apk_log.txt")); m_progressStream.putStream("Unpack APK starting"); if (m_apkFile.exists() && m_apkFile.isFile()) { // Extract all files except for XML, to be extracted later success = ApkZipUtil.unzipAllExceptXML(m_apkFile, m_appFolder, m_progressStream); ApkParser apkParser = ApkParser.create(m_apkFile.getStdFile()); ArrayList<OmniFile> dexFiles = new ArrayList<>(); // Get a list of all files in the APK and iterate and extract by type List<String> paths = OmniZip.getFilesList(m_apkFile); for (String path : paths) { OmniFile file = new OmniFile(m_volumeId, m_appFolderPath + path); OmniUtil.forceMkdirParent(file); String extension = FilenameUtils.getExtension(path); if (extension.contentEquals("xml")) { String xml = apkParser.transBinaryXml(path); OmniUtil.writeFile(file, xml); m_progressStream.putStream("Translated: " + path); } if (extension.contentEquals("dex")) { dexFiles.add(file); } } paths = null; // Release memory // Write over manifest with unencoded version String manifestXml = apkParser.getManifestXml(); OmniFile manifestFile = new OmniFile(m_volumeId, m_appFolderPath + "AndroidManifest.xml"); OmniUtil.writeFile(manifestFile, manifestXml); m_progressStream.putStream("Translated and parsed: " + "AndroidManifest.xml"); // Uses original author CaoQianLi's apk-parser // compile 'net.dongliu:apk-parser:2.1.7' // for( CertificateMeta cm : apkParser.getCertificateMetaList()){ // // m_progressStream.putStream("Certficate base64 MD5: "+cm.getCertBase64Md5()); // m_progressStream.putStream("Certficate MD5: "+cm.getCertMd5()); // m_progressStream.putStream("Sign algorithm OID: "+cm.getSignAlgorithmOID()); // m_progressStream.putStream("Sign algorithm: "+cm.getSignAlgorithm()); // } for (OmniFile f : dexFiles) { String formatted_count = String.format(Locale.US, "%,d", f.length()) + " bytes"; m_progressStream.putStream("DEX extracted: " + f.getName() + ": " + formatted_count); } dexFiles = new ArrayList<>();// Release memory CertificateMeta cm = null; try { cm = apkParser.getCertificateMeta(); m_progressStream.putStream("Certficate base64 MD5: " + cm.certBase64Md5); m_progressStream.putStream("Certficate MD5: " + cm.certMd5); m_progressStream.putStream("Sign algorithm OID: " + cm.signAlgorithmOID); m_progressStream.putStream("Sign algorithm: " + cm.signAlgorithm); } catch (Exception e1) { e1.printStackTrace(); } m_progressStream.putStream("ApkSignStatus: " + apkParser.verifyApk()); /** * Create a file for the user to include classes to omit in the optimize DEX task. */ OmniFile optimizedDexOF = new OmniFile(m_volumeId, m_appFolderPath + OPTIMIZED_CLASSES_EXCLUSION_FILENAME); if (!optimizedDexOF.exists()) { String assetFilePath = CConst.ASSET_DATA_FOLDER + OPTIMIZED_CLASSES_EXCLUSION_FILENAME; OmniFile omniFile = new OmniFile(m_volumeId, m_appFolderPath + OPTIMIZED_CLASSES_EXCLUSION_FILENAME); OmniUtil.copyAsset(m_ctx, assetFilePath, omniFile); m_progressStream.putStream("File created: " + OPTIMIZED_CLASSES_EXCLUSION_FILENAME); } /** * Create a README file for the user. */ OmniFile README_file = new OmniFile(m_volumeId, m_appFolderPath + README_FILENAME); if (!README_file.exists()) { String assetFilePath = CConst.ASSET_DATA_FOLDER + README_FILENAME; OmniFile omniFile = new OmniFile(m_volumeId, m_appFolderPath + README_FILENAME); OmniUtil.copyAsset(m_ctx, assetFilePath, omniFile); m_progressStream.putStream("File created: " + README_FILENAME); } } else { m_progressStream.putStream("APK not found. Select Extract APK."); } } catch (Exception | StackOverflowError e) { m_progressStream.putStream(e.toString()); } String time = TimeUtil.deltaTimeHrMinSec(m_unpack_apk_time); m_unpack_apk_time = 0; if (success) { m_progressStream.putStream("Unpack APK complete: " + time); } else { m_progressStream.putStream("Unpack APK failed: " + time); } m_progressStream.close(); } }, UNZIP_APK_THREAD, STACK_SIZE); m_unpackApkThread.setPriority(Thread.MAX_PRIORITY); m_unpackApkThread.setUncaughtExceptionHandler(uncaughtExceptionHandler); m_unpackApkThread.start(); final JSONObject wrapper = new JSONObject(); try { wrapper.put("unpack_apk_thread", getThreadStatus(true, m_unpackApkThread)); } catch (JSONException e) { LogUtil.logException(LogUtil.LogType.DECOMPILE, e); } return wrapper; }
From source file:com.wwidesigner.gui.StudyModel.java
/** * Set study model preferences from application preferences. * //from w w w.j a va2 s. c o m * @param newPreferences */ public void setPreferences(Preferences newPreferences) { double currentTemperature = newPreferences.getDouble(OptimizationPreferences.TEMPERATURE_OPT, OptimizationPreferences.DEFAULT_TEMPERATURE); double currentPressure = newPreferences.getDouble(OptimizationPreferences.PRESSURE_OPT, OptimizationPreferences.DEFAULT_PRESSURE); int currentHumidity = newPreferences.getInt(OptimizationPreferences.HUMIDITY_OPT, OptimizationPreferences.DEFAULT_HUMIDITY); int currentCO2 = newPreferences.getInt(OptimizationPreferences.CO2_FRACTION_OPT, OptimizationPreferences.DEFAULT_CO2_FRACTION); double xCO2 = currentCO2 * 1.0e-6; getParams().setProperties(currentTemperature, currentPressure, currentHumidity, xCO2); getParams().printProperties(); String optimizerPreference = newPreferences.get(OptimizationPreferences.OPTIMIZER_TYPE_OPT, OptimizationPreferences.OPT_DEFAULT_NAME); if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DEFAULT_NAME)) { preferredOptimizerType = null; } else if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DIRECT_NAME)) { preferredOptimizerType = BaseObjectiveFunction.OptimizerType.DIRECTOptimizer; } else { preferredOptimizerType = null; } }
From source file:com.mobshep.mobileshepherd.CSInjection2.java
public void onClick(View arg0) { switch (arg0.getId()) { case (R.id.bLogin): String Name = username.getText().toString(); String Pass = password.getText().toString(); Name = sanitizeValue(Name); Pass = sanitizeValue(Pass);//from w ww .java 2s . c o m try { if (login(Name, Pass) == true) { outputKey(this, dbPassword); Toast toast = Toast.makeText(CSInjection2.this, "Logged in!", Toast.LENGTH_LONG); toast.show(); } } catch (IOException e1) { Toast toast = Toast.makeText(CSInjection2.this, "An error occurred!", Toast.LENGTH_LONG); toast.show(); } try { if (login(Name, Pass) == false) { Toast toast = Toast.makeText(CSInjection2.this, "Invalid Credentials, " + Name, Toast.LENGTH_LONG); toast.show(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (Name.contentEquals("") || Pass.contentEquals("")) { Toast toast2 = Toast.makeText(CSInjection2.this, "Empty Fields Detected.", Toast.LENGTH_SHORT); toast2.show(); } } }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
public void uploadtoserver() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);// w w w. j a v a 2 s. c o m try { JSONArray arry = new JSONArray(BaseVideo.jsondata); RequestParams params = new RequestParams(); JSONObject obj = arry.getJSONObject(2); if (obj.has("button_id")) { Log.d("buttonid", String.valueOf(obj.getInt("button_id"))); params.put("button_id", String.valueOf(obj.getInt("button_id"))); } if (obj.has("id")) { Log.d("id", obj.getString("id")); params.put("id", obj.getString("id")); } if (obj.has("title")) { Log.d("title", obj.getString("title")); params.put("title", obj.getString("title").toString()); } if (obj.has("text")) { Log.d("text", obj.getString("text")); String txt = obj.getString("text").toString().replace("<p>", "").replace("</p>", ""); params.put("text", txt); // Toast.makeText(context, txt, Toast.LENGTH_LONG).show(); } // Html.fromHtml(obj.getString("description")).toString()); if (obj.has("description")) { Log.d("description", obj.getString("description")); params.put("description", obj.getString("description").toString()); } if (obj.has("api_key")) { Log.d("api_key", obj.getString("api_key")); params.put("api_key", obj.getString("api_key")); } if (obj.has("video")) { Log.d("video", "/sdcard/videokit/final.mp4"); params.put("video", new File("/sdcard/videokit/final.mp4")); } if (Constant.img_url != null) { Log.d("video_thumbnail_url", Constant.img_url); params.put("video_thumbnail_url", Constant.img_url); } else { // video_thumbnail if (obj.has("video_thumbnail")) { String image = obj.getString("video_thumbnail"); if (image != null) { Log.d("video_thumbnail", image); if (image.contains("content") || image.contains("file")) { String getString = getFileNameByUri(getApplicationContext(), Uri.parse(image)); String thumb = reporteds(getString); params.put("video_thumbnail", new File(thumb)); } else { String thumb = reporteds(image); params.put("video_thumbnail", new File(thumb)); } } else { String thumb = reporteds(video_thumbpath.getAbsolutePath()); params.put("video_thumbnail", new File(thumb)); Log.d("image path32", video_thumbpath.getAbsolutePath()); } } else { String thumb = reporteds(video_thumbpath.getAbsolutePath()); params.put("video_thumbnail", new File(thumb)); Log.d("image path33", video_thumbpath.getAbsolutePath()); } } if (obj.has("video_frame")) { String images = obj.getString("video_frame"); if (images != null) { Log.d("video_frame_url", images); if (images.contentEquals("null")) { } else if (images.contains("http") || images.contains("https")) { params.put("video_frame_url", images); } else if (Constant.frm_url != null) { params.put("video_frame_url", Constant.frm_url); } } } posted(arry, params); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.runnerup.export.UploadManager.java
@SuppressWarnings("null") public Uploader add(ContentValues config) { if (config == null) { System.err.println("Add null!"); assert (false); return null; }/*from w w w . ja v a 2 s .c o m*/ String uploaderName = config.getAsString(DB.ACCOUNT.NAME); if (uploaderName == null) { System.err.println("name not found!"); return null; } if (uploaders.containsKey(uploaderName)) { return uploaders.get(uploaderName); } Uploader uploader = null; if (uploaderName.contentEquals(RunKeeperUploader.NAME)) { uploader = new RunKeeperUploader(this); } else if (uploaderName.contentEquals(GarminUploader.NAME)) { uploader = new GarminUploader(this); } else if (uploaderName.contentEquals(FunBeatUploader.NAME)) { uploader = new FunBeatUploader(this); } else if (uploaderName.contentEquals(MapMyRunUploader.NAME)) { uploader = new MapMyRunUploader(this); } else if (uploaderName.contentEquals(NikePlus.NAME)) { uploader = new NikePlus(this); } else if (uploaderName.contentEquals(JoggSE.NAME)) { uploader = new JoggSE(this); } else if (uploaderName.contentEquals(Endomondo.NAME)) { uploader = new Endomondo(this); } else if (uploaderName.contentEquals(RunningAHEAD.NAME)) { uploader = new RunningAHEAD(this); } else if (uploaderName.contentEquals(RunnerUpLive.NAME)) { uploader = new RunnerUpLive(context); } else if (uploaderName.contentEquals(DigifitUploader.NAME)) { uploader = new DigifitUploader(this); } else if (uploaderName.contentEquals(Strava.NAME)) { uploader = new Strava(this); } else if (uploaderName.contentEquals(Facebook.NAME)) { uploader = new Facebook(context, this); } else if (uploaderName.contentEquals(GooglePlus.NAME)) { uploader = new GooglePlus(this); } else if (uploaderName.contentEquals(RuntasticUploader.NAME)) { uploader = new RuntasticUploader(this); } else if (uploaderName.contentEquals(GoogleFitUploader.NAME)) { uploader = new GoogleFitUploader(context, this); } if (uploader != null) { if (!config.containsKey(DB.ACCOUNT.FLAGS)) { if (BuildConfig.DEBUG) { String s = null; s.charAt(3); } } uploader.init(config); uploaders.put(uploaderName, uploader); uploadersById.put(uploader.getId(), uploader); } return uploader; }