/** * Find the Pack whose Language id is "idLang" and indice is "indice". * * @param idLang the Language id * @param indice the indice * @return the Pack whose Language id is "idLang" and indice is "indice" */ public static Pack findByIdLangAndIndice(int idLang, int indice) { DatabaseHelper dbh = DatabaseHelper.getInstance(MyApplication.getContext()); String query; Cursor cursor; Pack retour; query = "SELECT " + "id, " // 0 + "timestamp_pack, " // 1 + "timestamp_last_answer " // 2 + "FROM pack " + "WHERE id_language = " + idLang + " " + "AND indice = " + indice; cursor = dbh.getReadableDatabase().rawQuery(query, null); if (cursor.getCount() == 0) { retour = null; } else { cursor.moveToFirst(); retour = new Pack( cursor.getInt(0), Language.find(idLang), indice, cursor.getLong(1), cursor.getLong(2)); } cursor.close(); return retour; }
/** * Handles a NCIP LookupRequest service by returning hard-coded data. * * @param initData the LookupRequestInitiationData * @param serviceManager provides access to remote services * @return LookupRequestResponseData */ @Override public LookupRequestResponseData performService( LookupRequestInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) throws ServiceException { final LookupRequestResponseData responseData = new LookupRequestResponseData(); DummyRemoteServiceManager dummySvcMgr = (DummyRemoteServiceManager) serviceManager; // Put the bibliographic information into the response. BibliographicDescription bibDesc = new BibliographicDescription(); DummyDatabase.ItemInfo itemInfo = null; List<Problem> problems = null; if (initData.getItemId() != null && (initData.getUserId() != null || initData.getAuthenticationInputs() != null && !initData.getAuthenticationInputs().isEmpty())) { // Note: We don't validate the RequestType, despite its being required by NCIP. itemInfo = DummyDatabase.ItemInfo.getByBarcode(initData.getItemId().getItemIdentifierValue()); if (itemInfo == null) { problems = ServiceHelper.generateProblems( Version1LookupRequestProcessingError.UNKNOWN_REQUEST, "LookupRequest", null, "Item " + initData.getItemId().getItemIdentifierValue() + " not found."); } else if (itemInfo.userNo.compareToIgnoreCase(initData.getUserId().getUserIdentifierValue()) != 0) { problems = ServiceHelper.generateProblems( Version1LookupRequestProcessingError.UNKNOWN_REQUEST, "LookupRequest", null, "Item " + initData.getItemId().getItemIdentifierValue() + " found but User " + initData.getUserId().getUserIdentifierValue() + " does not match."); } } else if (initData.getRequestId() != null) { DummyDatabase.RequestInfo requestInfo = DummyDatabase.RequestInfo.getByRequestNo( initData.getRequestId().getRequestIdentifierValue()); if (requestInfo != null) { itemInfo = DummyDatabase.ItemInfo.getByBarcode(requestInfo.itemBarcode); if (itemInfo == null) { problems = ServiceHelper.generateProblems( Version1LookupRequestProcessingError.UNKNOWN_REQUEST, "LookupRequest", null, "Item " + initData.getItemId().getItemIdentifierValue() + " not found."); } } else { problems = ServiceHelper.generateProblems( Version1LookupRequestProcessingError.UNKNOWN_REQUEST, "LookupRequest", null, "Request " + initData.getRequestId().getRequestIdentifierValue() + " not found."); } } else { problems = ServiceHelper.generateProblems( Version1GeneralProcessingError.NEEDED_DATA_MISSING, "LookupRequest", null, "Either ItemId or RequestId is required."); } if (problems == null) { ItemId itemId = new ItemId(); itemId.setItemIdentifierValue(itemInfo.barcode); responseData.setItemId(itemId); if (initData.getRequestId() != null) { responseData.setRequestId(initData.getRequestId()); } DummyDatabase.HoldingInfo holdingInfo = itemInfo.holdingInfo; DummyDatabase.BibInfo bibInfo = holdingInfo.bibInfo; bibDesc.setTitle(bibInfo.title); BibliographicRecordId bibliographicRecordId = new BibliographicRecordId(); bibliographicRecordId.setBibliographicRecordIdentifier(bibInfo.bibNo); AgencyId agencyId = new AgencyId(dummySvcMgr.getLibraryName()); bibliographicRecordId.setAgencyId(agencyId); List<BibliographicRecordId> bibRecordIds = new ArrayList<BibliographicRecordId>(); bibRecordIds.add(bibliographicRecordId); bibDesc.setBibliographicRecordIds(bibRecordIds); Language language = Language.find(Version1Language.VERSION_1_LANGUAGE, bibInfo.language); bibDesc.setLanguage(language); // Item information DummyDatabase.CircStatus ilsCircStatus = itemInfo.circStatus; // Map from the Dummy ILS's circulation status values to the Scheme Value Pair used in NCIP. CirculationStatus circStatus; switch (ilsCircStatus) { case ON_ORDER: { circStatus = Version1CirculationStatus.IN_PROCESS; break; } case ON_SHELF: { circStatus = Version1CirculationStatus.AVAILABLE_ON_SHELF; break; } case CHECKED_OUT: { circStatus = Version1CirculationStatus.ON_LOAN; break; } case IN_TRANSIT: { circStatus = Version1CirculationStatus.IN_TRANSIT_BETWEEN_LIBRARY_LOCATIONS; break; } default: { circStatus = Version1CirculationStatus.CIRCULATION_STATUS_UNDEFINED; break; } } // Item Description ItemDescription itemDescription = new ItemDescription(); itemDescription.setCallNumber(itemInfo.callNo); if (holdingInfo != null) { HoldingsInformation holdingsInfo = new HoldingsInformation(); holdingsInfo.setUnstructuredHoldingsData(holdingInfo.summaryHoldings); itemDescription.setHoldingsInformation(holdingsInfo); } itemDescription.setNumberOfPieces(new BigDecimal(1)); // Assemble the ItemOptionalFields where most of the data is returned ItemOptionalFields itemOptionalFields = new ItemOptionalFields(); itemOptionalFields.setBibliographicDescription(bibDesc); itemOptionalFields.setCirculationStatus(circStatus); itemOptionalFields.setItemDescription(itemDescription); responseData.setItemOptionalFields(itemOptionalFields); } else if (problems == null) { problems = ServiceHelper.generateProblems( Version1GeneralProcessingError.TEMPORARY_PROCESSING_FAILURE, "LookupRequest", null, "Unknown logic error."); responseData.setProblems(problems); } else { responseData.setProblems(problems); } return responseData; }
@SuppressWarnings("unchecked") @Override protected LanguageEmbedding embedding( Token<HTMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { if (LOG) { LOGGER.log( Level.FINE, String.format( "HTMLTokenId$Language<HTMLTokenId>.embedding(...) called on removed token with %s token id. LanguagePath: %s", token.id(), languagePath), new IllegalStateException()); // NOI18N } String mimeType = null; switch (token.id()) { // BEGIN TOR MODIFICATIONS case VALUE_JAVASCRIPT: mimeType = JAVASCRIPT_MIMETYPE; if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { // TODO: // XXX Don't handle JavaScript for non-quoted attributes // (Or use separate state so I can do 0,0 as offsets there // Marek: AFAIK value of the onSomething methods is always javascript // so having the attribute unqouted doesn't make much sense - the html spec // allows only a-zA-Z characters in unqouted values so I belive // it is not possible to write reasonable js code - it ususally // contains some whitespaces, brackets, quotations etc. PartType ptype = token.partType(); int startSkipLength = ptype == PartType.COMPLETE || ptype == PartType.START ? 1 : 0; int endSkipLength = ptype == PartType.COMPLETE || ptype == PartType.END ? 1 : 0; // do not join css code sections in attribute value between each other, // only token parts inside one value return LanguageEmbedding.create( lang, startSkipLength, endSkipLength, (ptype == PartType.END || ptype == PartType.COMPLETE) ? false : true); } } break; // END TOR MODIFICATIONS case VALUE_CSS: mimeType = STYLE_MIMETYPE; if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { PartType ptype = token.partType(); if (token.isRemoved()) { // strange, but sometimes the embedding is requested on removed token which has // null image return null; } char firstChar = token.text().charAt(0); boolean quoted = firstChar == '\'' || firstChar == '"'; int startSkipLength = quoted && (ptype == PartType.COMPLETE || ptype == PartType.START) ? 1 : 0; int endSkipLength = quoted && (ptype == PartType.COMPLETE || ptype == PartType.END) ? 1 : 0; // do not join css code sections in attribute value between each other, // only token parts inside one value return LanguageEmbedding.create( lang, startSkipLength, endSkipLength, (ptype == PartType.END || ptype == PartType.COMPLETE) ? false : true); } } break; case SCRIPT: mimeType = JAVASCRIPT_MIMETYPE; break; case STYLE: mimeType = STYLE_MIMETYPE; break; } if (mimeType != null) { Language lang = Language.find(mimeType); if (lang == null) { return null; // no language found } else { return LanguageEmbedding.create(lang, 0, 0, true); } } return null; }
public void setLanguage(int idLanguage) { this.language = Language.find(idLanguage); }