當前位置: 首頁>>代碼示例>>Java>>正文


Java Metadata.get方法代碼示例

本文整理匯總了Java中org.apache.tika.metadata.Metadata.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Metadata.get方法的具體用法?Java Metadata.get怎麽用?Java Metadata.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.tika.metadata.Metadata的用法示例。


在下文中一共展示了Metadata.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateReleaseDate

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
/**
 * Generates the release date
 */
private Date generateReleaseDate(Metadata metadata)
{
   String date = metadata.get(XMPDM.RELEASE_DATE);
   if(date == null || date.length() == 0)
   {
      return null;
   }
      
   // Is it just a year?
   if(date.matches("\\d\\d\\d\\d"))
   {
      // Just a year, we need a full date
      // Go for the 1st of the 1st
      Calendar c = Calendar.getInstance();
      c.set(
            Integer.parseInt(date), Calendar.JANUARY, 1,
            0, 0, 0
      );
      c.set(Calendar.MILLISECOND, 0);
      return c.getTime();
   }
   
   // Treat as a normal date
   return makeDate(date);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:29,代碼來源:TikaAudioMetadataExtracter.java

示例2: generateDescription

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
/**
 * Generate the description
 * 
 * @param metadata     the metadata extracted from the file
 * @return          the description
 */
@SuppressWarnings("deprecation")
private String generateDescription(Metadata metadata)
{
    StringBuilder result = new StringBuilder();
    if (metadata.get(Metadata.TITLE) != null)
    {
        result.append(metadata.get(Metadata.TITLE));
        if (metadata.get(XMPDM.ALBUM) != null)
        {
           result
            .append(" - ")
            .append(metadata.get(XMPDM.ALBUM));
        }
        if (metadata.get(XMPDM.ARTIST) != null)
        {
           result
            .append(" (")
            .append(metadata.get(XMPDM.ARTIST))
            .append(")");
        }
    }
    
    return result.toString();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:31,代碼來源:TikaAudioMetadataExtracter.java

示例3: getMetadataValue

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
private String getMetadataValue(Metadata metadata, String key)
{
    if (metadata.isMultiValued(key))
    {
        String[] parts = metadata.getValues(key);
        
        // use Set to prevent duplicates
        Set<String> value = new LinkedHashSet<String>(parts.length);
        
        for (int i = 0; i < parts.length; i++)
        {
            value.add(parts[i]);
        }
        
        String valueStr = value.toString();
        
        // remove leading/trailing braces []
        return valueStr.substring(1, valueStr.length() - 1);
    }
    else
    {
        return metadata.get(key);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:25,代碼來源:TikaPoweredMetadataExtracter.java

示例4: extractSpecific

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
/**
 * Because some editors use JPEG_IMAGE_HEIGHT_TAG when
 * saving JPEG images , a more reliable source for
 * image size are the values provided by Tika
 * and not the exif/tiff metadata read from the file
 * This will override the tiff:Image size 
 * which gets embedded into the alfresco node properties
 * for jpeg files that contain such exif information
 */
@Override
protected Map<String, Serializable> extractSpecific(Metadata metadata,
     Map<String, Serializable> properties, Map<String,String> headers) 
{
    
    if(MimetypeMap.MIMETYPE_IMAGE_JPEG.equals(metadata.get(Metadata.CONTENT_TYPE)))                
    {
        //check if the image has exif information
        if(metadata.get(EXIF_IMAGE_WIDTH_TAG) != null && metadata.get(EXIF_IMAGE_HEIGHT_TAG) != null )
        {    
            //replace the exif size properties that will be embedded in the node with
            //the guessed dimensions from Tika
            putRawValue(TIFF.IMAGE_LENGTH.getName(), extractSize(metadata.get(JPEG_IMAGE_HEIGHT_TAG)), properties);
            putRawValue(TIFF.IMAGE_WIDTH.getName(), extractSize(metadata.get(JPEG_IMAGE_WIDTH_TAG)), properties);
        }
    }
    return properties;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:28,代碼來源:TikaAutoMetadataExtracter.java

示例5: setTikaFeature

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
private void setTikaFeature(Metadata metadata, Property property, FeatureMap fmap) {
  String value = metadata.get(property);
  if (value == null) {
    return;
  }

  value = value.trim();
  if (value.length() == 0) {
    return;
  }
  String key = property.getName().toUpperCase();
  if (fmap.containsKey(key)) {
    fmap.put("TIKA_" + key, value);
  }
  else {
    fmap.put(key, value);
    fmap.put("TIKA_" + key, value);
  }		
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:20,代碼來源:TikaFormat.java

示例6: generateDocument

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
public static LWDocument generateDocument(LWDocument document, Metadata metadata, ContentHandler content) {
  if (metadata != null) {
    for (String name : metadata.names()) {
      String value = metadata.get(name);
      document.addField(name, value);
    }
  }
  if (content != null) {
    String body = content.toString();
    if (body.length() > MAX_TERM_LENGTH_UTF) {
      body = body.substring(0, MAX_TERM_LENGTH_UTF);
    }
    document.addField("body", body);
  }
  return document;
}
 
開發者ID:lucidworks,項目名稱:solr-hadoop-common,代碼行數:17,代碼來源:TikaParsing.java

示例7: detectCharset

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
private static Charset detectCharset(final Path path, final Metadata metadata) throws IOException {
	final Charset charset;

	// Try to parse the character set from the content-encoding.
	String orig = metadata.get(Metadata.CONTENT_ENCODING);

	// Try to detect the character set.
	if (null != orig && Charset.isSupported(orig)) {
		return Charset.forName(orig);
	}

	try (
		final InputStream input = new BufferedInputStream(Files.newInputStream(path));
		final AutoDetectReader detector = new AutoDetectReader(input, metadata)
	) {
		charset = detector.getCharset();
	} catch (TikaException e) {
		throw new IOException("Unable to detect charset.", e);
	}

	return charset;
}
 
開發者ID:ICIJ,項目名稱:extract,代碼行數:23,代碼來源:DataURIEncodingInputStream.java

示例8: Convert

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
protected String Convert(InputStream Bytes) throws PDException
{  
try {                
ContentHandler textHandler=new BodyContentHandler(-1);
Metadata metadata=new Metadata();
Parser parser=new AutoDetectParser();
ParseContext context=new ParseContext();
parser.parse(Bytes, textHandler, metadata, context);
FileMetadata="";
for (String key : metadata.names()) 
    FileMetadata+=key+"="+metadata.get(key)+"\n";
FullText=textHandler.toString();
} catch (Exception ex)
    {
    PDException.GenPDException("Error_extracting_content_from_doc", ex.getLocalizedMessage());
    }

return(FullText); 
}
 
開發者ID:JHierrot,項目名稱:openprodoc,代碼行數:20,代碼來源:FTConnector.java

示例9: parse

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
@Override
	public final void parse(InputStream stream, ContentHandler handler,
			Metadata metadata, ParseContext context) throws IOException,
			SAXException, TikaException {
		if (metadata.get(Metadata.CONTENT_TYPE) == null) {
			throw new TikaException("No content type set");
		}

//		TaggedContentHandler tagged = new TaggedContentHandler(handler);
		ContentHandler wrappedHandler = getContentHandler(handler, metadata, context);
		
		if (wrappedHandler == null) {
			throw new TikaException("Parsing aborted, unable to init Tika handler");
		}

		try {
			context.getSAXParser().parse(new CloseShieldInputStream(stream),
					new OfflineContentHandler(wrappedHandler));
		} catch (Exception e) {
//			tagged.throwIfCauseOf(e);
			throw new TikaException("XML parse error", e);
		}
	}
 
開發者ID:erfgoed-en-locatie,項目名稱:artsholland-platform,代碼行數:24,代碼來源:AbstractParser.java

示例10: extractSpecific

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
    @Override
    protected Map<String, Serializable> extractSpecific(Metadata metadata,
         Map<String, Serializable> properties, Map<String, String> headers) 
    {
       putRawValue(KEY_CREATION_DATE, getDateOrNull(metadata.get(Metadata.CREATION_DATE)), properties);
       putRawValue(KEY_CREATOR, metadata.get(Metadata.CREATOR), properties);
       putRawValue(KEY_DATE, getDateOrNull(metadata.get(Metadata.DATE)), properties);
       putRawValue(KEY_DESCRIPTION, metadata.get(Metadata.DESCRIPTION), properties);
       putRawValue(KEY_GENERATOR, metadata.get("generator"), properties);
       putRawValue(KEY_INITIAL_CREATOR, metadata.get("initial-creator"), properties);
       putRawValue(KEY_KEYWORD, metadata.get(Metadata.KEYWORDS), properties);
       putRawValue(KEY_LANGUAGE, metadata.get(Metadata.LANGUAGE), properties);
//     putRawValue(KEY_PRINT_DATE, getDateOrNull(metadata.get(Metadata.)), rawProperties);
//     putRawValue(KEY_PRINTED_BY, metadata.get(Metadata.), rawProperties);
           
       // Handle user-defined properties dynamically
       Map<String, Set<QName>> mapping = super.getMapping();
       for (String key : mapping.keySet())
       {
           if (metadata.get(CUSTOM_PREFIX + key) != null)
           {
                putRawValue(key, metadata.get(CUSTOM_PREFIX + key), properties);
           }
       }
       
       return properties;
    }
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:29,代碼來源:OpenDocumentMetadataExtracter.java

示例11: select

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
@Override
public boolean select(Metadata metadata)
{
    String contentType = metadata.get(Metadata.CONTENT_TYPE);
    if (contentType == null || contentType.equals("") || disabledMediaTypes == null)
    {
        return true;
    }
    return !disabledMediaTypes.contains(contentType);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:11,代碼來源:MediaTypeDisablingDocumentSelector.java

示例12: UniversalEncodingListener

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
public UniversalEncodingListener(Metadata metadata) {
    MediaType type = MediaType.parse(metadata.get(Metadata.CONTENT_TYPE));
    if (type != null) {
        hint = type.getParameters().get("charset");
    }
    if (hint == null) {
        hint = metadata.get(Metadata.CONTENT_ENCODING);
    }
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:10,代碼來源:UniversalEncodingListener.java

示例13: getMetaData

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
public static String getMetaData(InputStream input, String metaData) throws IOException {
	String result = "";
	try {
		ContentHandler handler = new DefaultHandler();
		Metadata metadata = new Metadata();
		Parser parser = new AutoDetectParser();
		parser.parse(input, handler, metadata, new ParseContext());
		result = metadata.get(metaData);
	} catch (Exception e) {
	} finally {
		if (input != null)
			input.close();
	}
	return result;
}
 
開發者ID:regestaexe,項目名稱:bygle-ldp,代碼行數:16,代碼來源:FileInfoReader.java

示例14: assembleExtractionResult

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
private String assembleExtractionResult(String bucket, String key, String extractedText, Metadata tikaMetadata) {

      JSONObject extractJson = new JSONObject();

      String contentType = tikaMetadata.get("Content-Type");
      contentType = contentType != null ? contentType : "content/unknown";

      String contentLength = tikaMetadata.get("Content-Length");
      contentLength = contentLength != null ? contentLength : "0";

      extractJson.put("Exception", null);
      extractJson.put("FilePath", "s3://" + bucket + "/" + key);
      extractJson.put("Text", extractedText);
      extractJson.put("ContentType", contentType);
      extractJson.put("ContentLength", contentLength);

      JSONObject metadataJson = new JSONObject();

      for( String name : tikaMetadata.names() ){
        String[] elements = tikaMetadata.getValues(name);
        String joined = String.join(", ", elements);
        metadataJson.put(name, joined);
      }

      extractJson.put("Metadata", metadataJson);

      return extractJson.toJSONString();
    }
 
開發者ID:DovetailSoftware,項目名稱:tika-lambda,代碼行數:29,代碼來源:TikaLambdaHandler.java

示例15: parse

import org.apache.tika.metadata.Metadata; //導入方法依賴的package包/類
@Override
public void parse(final InputStream stream, final ContentHandler handler, final Metadata metadata,
                  final ParseContext context) throws SAXException, IOException, TikaException {
	final Parser parser;
	final long size;
	String value = metadata.get(Metadata.CONTENT_LENGTH);

	if (null != value && !value.isEmpty()) {
		size = Long.valueOf(value);
	} else {
		try (final TikaInputStream tis = TikaInputStream.get(stream)) {
			size = tis.getLength();
		}

		metadata.set(Metadata.CONTENT_LENGTH, Long.toString(size));
	}

	// If the file is not empty, throw a parse error.
	// Otherwise, output an empty document.
	if (size > 0) {
		parser = ErrorParser.INSTANCE;
	} else {
		metadata.set(Metadata.CONTENT_TYPE, "application/octet-stream");
		parser = EmptyParser.INSTANCE;
	}

	parser.parse(stream, handler, metadata, context);
}
 
開發者ID:ICIJ,項目名稱:extract,代碼行數:29,代碼來源:FallbackParser.java


注:本文中的org.apache.tika.metadata.Metadata.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。