List of usage examples for org.apache.lucene.document Field toString
@Override
public String toString()
From source file:com.sun.javaee.blueprints.carstore.search.SearchIndex.java
License:Berkeley License
public List<IndexDocument> query(String indexFile, String searchString, String searchField) { Searcher searcher = null;//from w w w . ja v a 2 s. c om try { searcher = new IndexSearcher(indexFile); Analyzer analyzer = new StandardAnalyzer(); // search "contents" attribute by default where all relavant words are kept QueryParser queryParser = new QueryParser(searchField, analyzer); queryParser.setDefaultOperator(QueryParser.Operator.AND); Query query = queryParser.parse(searchString); CarstoreUtil.getLogger().log(Level.INFO, "search.string", searchString); // execute search hits = searcher.search(query); CarstoreUtil.getLogger().log(Level.INFO, "search.results", String.valueOf(hits.length())); Document indexDoc; Enumeration enumx; Field fieldx; IndexDocument indexDocument = null; for (int ii = 0; ii < hits.length(); ii++) { indexDoc = hits.doc(ii); // create new holder for research results indexDocument = new IndexDocument(); fieldx = indexDoc.getField("url"); if (fieldx != null) { indexDocument.setPageURL(fieldx.stringValue()); } fieldx = indexDoc.getField("uid"); if (fieldx != null) { indexDocument.setUID(fieldx.stringValue()); } fieldx = indexDoc.getField("summary"); if (fieldx != null) { indexDocument.setSummary(fieldx.stringValue()); } fieldx = indexDoc.getField("title"); if (fieldx != null) { indexDocument.setTitle(fieldx.stringValue()); } fieldx = indexDoc.getField("image"); if (fieldx != null) { indexDocument.setImage(fieldx.stringValue()); } fieldx = indexDoc.getField("price"); if (fieldx != null) { indexDocument.setPrice(fieldx.stringValue()); } fieldx = indexDoc.getField("product"); if (fieldx != null) { indexDocument.setProduct(fieldx.stringValue()); } fieldx = indexDoc.getField("contents"); if (fieldx != null) { indexDocument.setContents(fieldx.stringValue()); } fieldx = indexDoc.getField("modified"); if (fieldx != null) { indexDocument.setModifiedDate(fieldx.stringValue()); } fieldx = indexDoc.getField("tag"); if (fieldx != null) { indexDocument.setTag(fieldx.stringValue()); } fieldx = indexDoc.getField("disabled"); if (fieldx != null) { indexDocument.setDisabled(fieldx.stringValue()); } // list all attributes indexed String outx = "\nDocument" + indexDoc.toString() + "\n"; if (bDebug) { enumx = indexDoc.fields(); while (enumx.hasMoreElements()) { fieldx = (Field) enumx.nextElement(); outx += "\tField - " + fieldx.toString() + "\n"; outx += "\t\t" + fieldx.name() + " - " + fieldx.stringValue() + "\n"; } System.out.println(outx); } hitsList.add(indexDocument); } } catch (Exception e) { CarstoreUtil.getLogger().log(Level.WARNING, "search.exception", e); e.printStackTrace(); } finally { if (searcher != null) { try { // make sure close search or index files get locked searcher.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } return hitsList; }
From source file:com.sun.javaee.blueprints.petstore.search.SearchIndex.java
License:Berkeley License
public List<IndexDocument> query(String indexFile, String searchString, String searchField) { Searcher searcher = null;// w w w . j a v a2 s. c o m try { searcher = new IndexSearcher(indexFile); Analyzer analyzer = new StandardAnalyzer(); // search "contents" attribute by default where all relavant words are kept QueryParser queryParser = new QueryParser(searchField, analyzer); queryParser.setDefaultOperator(QueryParser.Operator.AND); Query query = queryParser.parse(searchString); PetstoreUtil.getLogger().log(Level.INFO, "search.string", searchString); // execute search hits = searcher.search(query); PetstoreUtil.getLogger().log(Level.INFO, "search.results", String.valueOf(hits.length())); Document indexDoc; Enumeration enumx; Field fieldx; IndexDocument indexDocument = null; for (int ii = 0; ii < hits.length(); ii++) { indexDoc = hits.doc(ii); // create new holder for research results indexDocument = new IndexDocument(); fieldx = indexDoc.getField("url"); if (fieldx != null) { indexDocument.setPageURL(fieldx.stringValue()); } fieldx = indexDoc.getField("uid"); if (fieldx != null) { indexDocument.setUID(fieldx.stringValue()); } fieldx = indexDoc.getField("summary"); if (fieldx != null) { indexDocument.setSummary(fieldx.stringValue()); } fieldx = indexDoc.getField("title"); if (fieldx != null) { indexDocument.setTitle(fieldx.stringValue()); } fieldx = indexDoc.getField("image"); if (fieldx != null) { indexDocument.setImage(fieldx.stringValue()); } fieldx = indexDoc.getField("price"); if (fieldx != null) { indexDocument.setPrice(fieldx.stringValue()); } fieldx = indexDoc.getField("product"); if (fieldx != null) { indexDocument.setProduct(fieldx.stringValue()); } fieldx = indexDoc.getField("contents"); if (fieldx != null) { indexDocument.setContents(fieldx.stringValue()); } fieldx = indexDoc.getField("modified"); if (fieldx != null) { indexDocument.setModifiedDate(fieldx.stringValue()); } fieldx = indexDoc.getField("tag"); if (fieldx != null) { indexDocument.setTag(fieldx.stringValue()); } fieldx = indexDoc.getField("disabled"); if (fieldx != null) { indexDocument.setDisabled(fieldx.stringValue()); } // list all attributes indexed String outx = "\nDocument" + indexDoc.toString() + "\n"; if (bDebug) { enumx = indexDoc.fields(); while (enumx.hasMoreElements()) { fieldx = (Field) enumx.nextElement(); outx += "\tField - " + fieldx.toString() + "\n"; outx += "\t\t" + fieldx.name() + " - " + fieldx.stringValue() + "\n"; } System.out.println(outx); } hitsList.add(indexDocument); } } catch (Exception e) { PetstoreUtil.getLogger().log(Level.WARNING, "search.exception", e); e.printStackTrace(); } finally { if (searcher != null) { try { // make sure close search or index files get locked searcher.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } return hitsList; }
From source file:com.zimbra.cs.index.IndexEditor.java
License:Open Source License
public void dumpDocument(Document d, boolean isDeleted) { if (isDeleted) { outputStream.print("DELETED "); }//from ww w. jav a 2 s .co m String subj, blobId; Field f; f = d.getField(LuceneFields.L_H_SUBJECT); if (f != null) { subj = f.stringValue(); } else { subj = "MISSING_SUBJECT"; } f = d.getField(LuceneFields.L_MAILBOX_BLOB_ID); if (f != null) { blobId = f.stringValue(); } else { blobId = "MISSING"; } String dateStr = d.get(LuceneFields.L_SORT_DATE); if (dateStr == null) { dateStr = ""; } else { try { Date dt = DateTools.stringToDate(dateStr); dateStr = dt.toString() + " (" + dt.getTime() + ")"; } catch (java.text.ParseException e) { assert false; } } String sizeStr = d.get(LuceneFields.L_SORT_SIZE); if (sizeStr == null) { sizeStr = ""; } String part = d.get(LuceneFields.L_PARTNAME); if (part == null) { part = "NO_PART"; } outputStream.println(Format(blobId, 10) + Format(dateStr, 45) + Format(part, 10) + Format(sizeStr, 10) + "\"" + subj + "\""); Field content = d.getField(LuceneFields.L_CONTENT); if (content != null) { outputStream.println("\t" + content.toString()); } }
From source file:it.unibz.instasearch.indexing.Searcher.java
License:Open Source License
/** * Get all terms that start with prefixText * @param prefixText//from w ww. ja v a 2 s . c o m * @param prefixField * * @return proposed terms * @throws IOException */ public List<String> getProposals(String prefixText, Field prefixField) throws IOException { ArrayList<String> proposals = new ArrayList<String>(); IndexReader reader = getIndexSearcher().getIndexReader(); Term prefix = prefixField.createTerm(prefixText); TermEnum enumerator = reader.terms(prefix); prefixText = prefixText.toLowerCase(); try { do { Term term = enumerator.term(); if (term != null && term.text().toLowerCase().startsWith(prefixText) && term.field().equalsIgnoreCase(prefixField.toString())) { proposals.add(term.text()); } else { break; } } while (enumerator.next()); } finally { enumerator.close(); } return proposals; }
From source file:it.unibz.instasearch.indexing.SearchResultDoc.java
License:Open Source License
private String getFieldValue(Field field) { return doc.get(field.toString()); }
From source file:it.unibz.instasearch.indexing.StorageIndexer.java
License:Open Source License
private static org.apache.lucene.document.Field createLuceneField(Field fieldName, String value) { return new org.apache.lucene.document.Field(fieldName.toString(), value, Store.YES, org.apache.lucene.document.Field.Index.NOT_ANALYZED); }
From source file:it.unibz.instasearch.indexing.StorageIndexer.java
License:Open Source License
private static org.apache.lucene.document.Field createLuceneField(Field fieldName, Reader reader) { return new org.apache.lucene.document.Field(fieldName.toString(), reader, TermVector.YES); }
From source file:org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex.java
License:Apache License
/** * Create a new {@link Document} for the given {@link MailboxMessage}. This Document does not contain any flags data. The {@link Flags} are stored in a seperate Document. * /*from w ww.j ava 2 s . c o m*/ * See {@link #createFlagsDocument(MailboxMessage)} * * @param membership * @return document */ private Document createMessageDocument(final MailboxSession session, final MailboxMessage membership) throws MailboxException { final Document doc = new Document(); // TODO: Better handling doc.add(new Field(MAILBOX_ID_FIELD, membership.getMailboxId().serialize().toUpperCase(Locale.ENGLISH), Store.YES, Index.NOT_ANALYZED)); doc.add(new NumericField(UID_FIELD, Store.YES, true).setLongValue(membership.getUid().asLong())); if (shouldIndexMessageId == IndexMessageId.Required) { doc.add(new Field(MESSAGE_ID_FIELD, membership.getMessageId().serialize(), Store.YES, Index.NOT_ANALYZED)); } // create an unqiue key for the document which can be used later on updates to find the document doc.add(new Field(ID_FIELD, membership.getMailboxId().serialize().toUpperCase(Locale.ENGLISH) + "-" + Long.toString(membership.getUid().asLong()), Store.YES, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_YEAR_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.YEAR), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_MONTH_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.MONTH), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_DAY_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.DAY), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_HOUR_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.HOUR), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_MINUTE_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.MINUTE), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_SECOND_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.SECOND), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(INTERNAL_DATE_FIELD_MILLISECOND_RESOLUTION, DateTools.dateToString(membership.getInternalDate(), DateTools.Resolution.MILLISECOND), Store.NO, Index.NOT_ANALYZED)); doc.add(new NumericField(SIZE_FIELD, Store.YES, true).setLongValue(membership.getFullContentOctets())); // content handler which will index the headers and the body of the message SimpleContentHandler handler = new SimpleContentHandler() { public void headers(Header header) { Date sentDate = null; String firstFromMailbox = ""; String firstToMailbox = ""; String firstCcMailbox = ""; String firstFromDisplay = ""; String firstToDisplay = ""; Iterator<org.apache.james.mime4j.stream.Field> fields = header.iterator(); while (fields.hasNext()) { org.apache.james.mime4j.stream.Field f = fields.next(); String headerName = f.getName().toUpperCase(Locale.ENGLISH); String headerValue = f.getBody().toUpperCase(Locale.ENGLISH); String fullValue = f.toString().toUpperCase(Locale.ENGLISH); doc.add(new Field(HEADERS_FIELD, fullValue, Store.NO, Index.ANALYZED)); doc.add(new Field(PREFIX_HEADER_FIELD + headerName, headerValue, Store.NO, Index.ANALYZED)); if (f instanceof DateTimeField) { // We need to make sure we convert it to GMT final StringReader reader = new StringReader(f.getBody()); try { DateTime dateTime = new DateTimeParser(reader).parseAll(); Calendar cal = getGMT(); cal.set(dateTime.getYear(), dateTime.getMonth() - 1, dateTime.getDay(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond()); sentDate = cal.getTime(); } catch (org.apache.james.mime4j.field.datetime.parser.ParseException e) { session.getLog().debug("Unable to parse Date header for proper indexing", e); // This should never happen anyway fallback to the already parsed field sentDate = ((DateTimeField) f).getDate(); } } String field = null; if ("To".equalsIgnoreCase(headerName)) { field = TO_FIELD; } else if ("From".equalsIgnoreCase(headerName)) { field = FROM_FIELD; } else if ("Cc".equalsIgnoreCase(headerName)) { field = CC_FIELD; } else if ("Bcc".equalsIgnoreCase(headerName)) { field = BCC_FIELD; } // Check if we can index the the address in the right manner if (field != null) { // not sure if we really should reparse it. It maybe be better to check just for the right type. // But this impl was easier in the first place AddressList aList = LenientAddressParser.DEFAULT .parseAddressList(MimeUtil.unfold(f.getBody())); for (int i = 0; i < aList.size(); i++) { Address address = aList.get(i); if (address instanceof org.apache.james.mime4j.dom.address.Mailbox) { org.apache.james.mime4j.dom.address.Mailbox mailbox = (org.apache.james.mime4j.dom.address.Mailbox) address; String value = AddressFormatter.DEFAULT.encode(mailbox).toUpperCase(Locale.ENGLISH); doc.add(new Field(field, value, Store.NO, Index.ANALYZED)); if (i == 0) { String mailboxAddress = SearchUtil.getMailboxAddress(mailbox); String mailboxDisplay = SearchUtil.getDisplayAddress(mailbox); if ("To".equalsIgnoreCase(headerName)) { firstToMailbox = mailboxAddress; firstToDisplay = mailboxDisplay; } else if ("From".equalsIgnoreCase(headerName)) { firstFromMailbox = mailboxAddress; firstFromDisplay = mailboxDisplay; } else if ("Cc".equalsIgnoreCase(headerName)) { firstCcMailbox = mailboxAddress; } } } else if (address instanceof Group) { MailboxList mList = ((Group) address).getMailboxes(); for (int a = 0; a < mList.size(); a++) { org.apache.james.mime4j.dom.address.Mailbox mailbox = mList.get(a); String value = AddressFormatter.DEFAULT.encode(mailbox) .toUpperCase(Locale.ENGLISH); doc.add(new Field(field, value, Store.NO, Index.ANALYZED)); if (i == 0 && a == 0) { String mailboxAddress = SearchUtil.getMailboxAddress(mailbox); String mailboxDisplay = SearchUtil.getDisplayAddress(mailbox); if ("To".equalsIgnoreCase(headerName)) { firstToMailbox = mailboxAddress; firstToDisplay = mailboxDisplay; } else if ("From".equalsIgnoreCase(headerName)) { firstFromMailbox = mailboxAddress; firstFromDisplay = mailboxDisplay; } else if ("Cc".equalsIgnoreCase(headerName)) { firstCcMailbox = mailboxAddress; } } } } } doc.add(new Field(field, headerValue, Store.NO, Index.ANALYZED)); } else if (headerName.equalsIgnoreCase("Subject")) { doc.add(new Field(BASE_SUBJECT_FIELD, SearchUtil.getBaseSubject(headerValue), Store.YES, Index.NOT_ANALYZED)); } } if (sentDate == null) { sentDate = membership.getInternalDate(); } else { doc.add(new Field(SENT_DATE_FIELD_YEAR_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.YEAR), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_MONTH_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.MONTH), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_DAY_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.DAY), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_HOUR_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.HOUR), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_MINUTE_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.MINUTE), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_SECOND_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.SECOND), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(SENT_DATE_FIELD_MILLISECOND_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.MILLISECOND), Store.NO, Index.NOT_ANALYZED)); } doc.add(new Field(SENT_DATE_SORT_FIELD_MILLISECOND_RESOLUTION, DateTools.dateToString(sentDate, DateTools.Resolution.MILLISECOND), Store.NO, Index.NOT_ANALYZED)); doc.add(new Field(FIRST_FROM_MAILBOX_NAME_FIELD, firstFromMailbox, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field(FIRST_TO_MAILBOX_NAME_FIELD, firstToMailbox, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field(FIRST_CC_MAILBOX_NAME_FIELD, firstCcMailbox, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field(FIRST_FROM_MAILBOX_DISPLAY_FIELD, firstFromDisplay, Store.YES, Index.NOT_ANALYZED)); doc.add(new Field(FIRST_TO_MAILBOX_DISPLAY_FIELD, firstToDisplay, Store.YES, Index.NOT_ANALYZED)); } @Override public void body(BodyDescriptor desc, InputStream in) throws MimeException, IOException { String mediaType = desc.getMediaType(); if (MEDIA_TYPE_TEXT.equalsIgnoreCase(mediaType) || MEDIA_TYPE_MESSAGE.equalsIgnoreCase(mediaType)) { String cset = desc.getCharset(); if (cset == null) { cset = DEFAULT_ENCODING; } Charset charset; try { charset = Charset.forName(cset); } catch (Exception e) { // Invalid charset found so fallback toe the DEFAULT_ENCODING charset = Charset.forName(DEFAULT_ENCODING); } // Read the content one line after the other and add it to the document BufferedReader bodyReader = new BufferedReader(new InputStreamReader(in, charset)); String line = null; while ((line = bodyReader.readLine()) != null) { doc.add(new Field(BODY_FIELD, line.toUpperCase(Locale.ENGLISH), Store.NO, Index.ANALYZED)); } } } }; MimeConfig config = MimeConfig.custom().setMaxLineLen(-1).setMaxContentLen(-1).build(); //config.setStrictParsing(false); MimeStreamParser parser = new MimeStreamParser(config); parser.setContentDecoding(true); parser.setContentHandler(handler); try { // parse the message to index headers and body parser.parse(membership.getFullContent()); } catch (MimeException e) { // This should never happen as it was parsed before too without problems. throw new MailboxException("Unable to index content of message", e); } catch (IOException e) { // This should never happen as it was parsed before too without problems. // anyway let us just skip the body and headers in the index throw new MailboxException("Unable to index content of message", e); } return doc; }
From source file:org.ariadne_eu.oai.server.lucene.crosswalk.Lucene2oai_ese.java
License:Creative Commons License
public String createMetadata(Object nativeItem) throws CannotDisseminateFormatException { //Cast the nativeItem to your object Document doc = (Document) nativeItem; List fieldsList = doc.getFields(); List<org.apache.lucene.document.Field> fieldsNodes = doc.getFields(); for (org.apache.lucene.document.Field element : fieldsNodes) { System.out.println("The fields are:" + element.toString()); }/*from ww w.ja va2 s .c o m*/ Element record = new Element("record", esens); record.addNamespaceDeclaration(europeanans); record.addNamespaceDeclaration(dcns); record.setAttribute("schemaLocation", "http://www.europeana.eu/schemas/ese/ http://www.europeana.eu/schemas/ese/ESE-V3.4.xsd", xsi); // record.setAttribute("dc","http://purl.org/dc/elements/1.1/",dcns); //dc:identifier Element identifier = new Element("identifier", dcns); record.addContent(identifier); if (doc.getField("lom.general.identifier.entry") != null) { String idString = doc.getField("lom.general.identifier.entry").stringValue(); if (idString != null) identifier.setText(idString); } //dc:title Element title = new Element("title", dcns); record.addContent(title); if (doc.getField("lom.general.title.string") != null) { String titleString = doc.getField("lom.general.title.string").stringValue(); if (titleString != null) title.setText(titleString); } //dc:language if (doc.getField("lom.general.language") != null) { Element language = new Element("language", dcns); record.addContent(language); String languageSrt = doc.getField("lom.general.language").stringValue(); if (languageSrt != null) language.setText(languageSrt); } //dc:description Element descr = new Element("description", dcns); record.addContent(descr); if (doc.getField("lom.general.description.string") != null) { String descrString = doc.getField("lom.general.description.string").stringValue(); if (descrString != null) descr.setText(descrString); } //dc:subject Field[] keyNodes = doc.getFields("lom.general.keyword.string"); for (org.apache.lucene.document.Field element : keyNodes) { String theString = element.stringValue(); if (theString != null && !theString.trim().isEmpty()) { Element subject = new Element("subject", dcns); record.addContent(subject); subject.setText(theString); } } //dc:format Element format = new Element("format", dcns); record.addContent(format); if (doc.getField("lom.technical.format") != null) { String formatString = doc.getField("lom.technical.format").stringValue(); if (formatString != null) format.setText(formatString); } //dcterms:spatial if (doc.getFields("lom.general.coverage.string") != null) { Field[] spatNodes = doc.getFields("lom.general.coverage.string"); for (org.apache.lucene.document.Field element : spatNodes) { String theString = element.stringValue(); if (theString != null && !theString.trim().isEmpty()) { Element coverage = new Element("spatial", dctermsns); record.addContent(coverage); coverage.setText(theString); } } } //dcterms:temploral if (doc.getFields("lom.educational.typicalAgeRange") != null) { Field[] tempNodes = doc.getFields("lom.educational.typicalAgeRange"); for (org.apache.lucene.document.Field element : tempNodes) { String theString = element.stringValue(); if (theString != null && !theString.trim().isEmpty()) { Element temporal = new Element("temporal", dctermsns); record.addContent(temporal); temporal.setText(theString); } } } //europeana:object if (doc.getField("lom.technical.duration") != null) { Element object = new Element("object", europeanans); record.addContent(object); String thumbString = doc.getField("lom.technical.duration").stringValue(); if (thumbString != null) object.setText(thumbString); } //europeana:provider Element provider = new Element("provider", europeanans); record.addContent(provider); provider.setText("The Natural Europe Project"); // europeana:type // When europeana:type is "TEXT" then a value for "dc:language must be provided". Element type_eu = new Element("type", europeanans); record.addContent(type_eu); if (doc.getField("lom.technical.format") != null) { String typeString = doc.getField("lom.technical.format").stringValue(); type_eu.setText(typeString); if (typeString != null) { if (typeString.contains("image") || typeString.contains("jpeg") || typeString.contains("jpg")) type_eu.setText("IMAGE"); else if (typeString.contains("video")) type_eu.setText("VIDEO"); else if (typeString.contains("pdf") || typeString.contains("text")) type_eu.setText("TEXT"); } } //europeana:rights Element rights = new Element("rights", europeanans); record.addContent(rights); if (doc.getField("lom.rights.copyrightandotherrestrictions.string") != null) { String rightsString = doc.getField("lom.rights.copyrightandotherrestrictions.string").stringValue(); rightsString = "http://creativecommons.org/licenses/" + rightsString + "/3.0/"; rights.setText(rightsString); } //europeana:dataProvider Element dataProvider = new Element("dataProvider", europeanans); record.addContent(dataProvider); if (doc.getField("lom.metametadata.identifier.catalog") != null) { String dataProviderString = doc.getField("lom.metametadata.identifier.catalog").stringValue(); if (dataProviderString != null) dataProvider.setText(dataProviderString); } //europeana:isShownBy Element isShownBy = new Element("isShownBy", europeanans); record.addContent(isShownBy); if (doc.getField("lom.technical.location") != null) { String locationString = doc.getField("lom.technical.location").stringValue(); if (locationString != null) isShownBy.setText(locationString); } //europeana:isShownAt String result = ""; result = OaiUtils.parseLom2Xmlstring(record); return result; }
From source file:org.eu.bitzone.Leia.java
License:Apache License
public void clipCopyFields(final Object table) { final Object[] rows = getSelectedItems(table); if (rows == null || rows.length == 0) { return;/*from w w w .jav a2s.c om*/ } final Document doc = (Document) getProperty(table, "doc"); if (doc == null) { return; } final StringBuffer sb = new StringBuffer(); for (int i = 0; i < rows.length; i++) { final Field f = (Field) getProperty(rows[i], "field"); if (f == null) { continue; } if (i > 0) { sb.append('\n'); } sb.append(f.toString()); } final StringSelection sel = new StringSelection(sb.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, this); }