本文整理了Java中org.apache.tika.metadata.Property
类的一些代码示例,展示了Property
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Property
类的具体详情如下:
包路径:org.apache.tika.metadata.Property
类名称:Property
[英]XMP property definition. Each instance of this class defines a single metadata property like "dc:format". In addition to the property name, the ValueType and category (internal or external) of the property are included in the property definition. The available choice values are also stored for open and closed choice value types.
[中]XMP属性定义。这个类的每个实例都定义了一个元数据属性,比如“dc:format”。除特性名称外,特性定义中还包括特性的ValueType和类别(内部或外部)。可用的选项值也存储为打开和关闭选项值类型。
代码示例来源:origin: apache/tika
public void indexWithDublinCore(File file) throws Exception {
Metadata met = new Metadata();
met.add(TikaCoreProperties.CREATOR, "Manning");
met.add(TikaCoreProperties.CREATOR, "Tika in Action");
met.set(TikaCoreProperties.CREATED, new Date());
met.set(TikaCoreProperties.FORMAT, tika.detect(file));
met.set(DublinCore.SOURCE, file.toURI().toURL().toString());
met.add(TikaCoreProperties.SUBJECT, "File");
met.add(TikaCoreProperties.SUBJECT, "Indexing");
met.add(TikaCoreProperties.SUBJECT, "Metadata");
met.set(Property.externalClosedChoise(TikaCoreProperties.RIGHTS.getName(), "public",
"private"), "public");
try (InputStream is = new FileInputStream(file)) {
tika.parse(is, met);
Document document = new Document();
for (String key : met.names()) {
String[] values = met.getValues(key);
for (String val : values) {
document.add(new TextField(key, val, Store.YES));
}
writer.addDocument(document);
}
}
}
}
代码示例来源:origin: apache/tika
if (metadata.isMultiValued(name)) {
List<String> previous = Arrays.asList(metadata.getValues(name));
if (!previous.contains(value)) {
if (property != null) {
metadata.add(property, value);
} else {
metadata.add(name, value);
if (!previous.equals(value)) {
if (property != null) {
if (property.isMultiValuePermitted()) {
metadata.add(property, value);
} else {
代码示例来源:origin: apache/tika
/**
* It will set all simple and array properties that have QName keys in registered namespaces.
*
* @see org.apache.tika.metadata.Metadata#setAll(java.util.Properties)
*/
@Override
public void setAll(Properties properties) {
@SuppressWarnings("unchecked")
Enumeration<String> names = (Enumeration<String>) properties.propertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
Property property = Property.get( name );
if (property == null) {
throw new PropertyTypeException( "Unknown property: " + name );
}
String value = properties.getProperty( name );
if (property.isMultiValuePermitted()) {
this.set( property, new String[] { value } );
}
else {
this.set( property, value );
}
}
}
代码示例来源:origin: apache/tika
/**
* Sets the real or rational value of the identified metadata property.
*
* @since Apache Tika 0.8
* @param property simple real or simple rational property definition
* @param value property value
*/
public void set(Property property, double value) {
if(property.getPrimaryProperty().getPropertyType() != Property.PropertyType.SIMPLE) {
throw new PropertyTypeException(Property.PropertyType.SIMPLE, property.getPrimaryProperty().getPropertyType());
}
if(property.getPrimaryProperty().getValueType() != Property.ValueType.REAL &&
property.getPrimaryProperty().getValueType() != Property.ValueType.RATIONAL) {
throw new PropertyTypeException(Property.ValueType.REAL, property.getPrimaryProperty().getValueType());
}
set(property, Double.toString(value));
}
代码示例来源:origin: apache/tika
/**
* Returns the value of the identified Date based metadata property.
*
* @since Apache Tika 0.8
* @param property simple date property definition
* @return property value as a Date, or <code>null</code> if the property is not set, or not a valid Date
*/
public Date getDate(Property property) {
if(property.getPrimaryProperty().getPropertyType() != Property.PropertyType.SIMPLE) {
return null;
}
if(property.getPrimaryProperty().getValueType() != Property.ValueType.DATE) {
return null;
}
String v = get(property);
if (v != null) {
return parseDate(v);
} else {
return null;
}
}
代码示例来源:origin: apache/tika
/**
* Sets the values of the identified metadata property.
*
* @since Apache Tika 1.2
* @param property property definition
* @param values property values
*/
public void set(Property property, String[] values) {
if (property == null) {
throw new NullPointerException("property must not be null");
}
if (property.getPropertyType() == PropertyType.COMPOSITE) {
set(property.getPrimaryProperty(), values);
if (property.getSecondaryExtractProperties() != null) {
for (Property secondaryExtractProperty : property.getSecondaryExtractProperties()) {
set(secondaryExtractProperty, values);
}
}
} else {
metadata.put(property.getName(), values);
}
}
代码示例来源:origin: apache/tika
/**
* Defines a composite property, then checks that when set as the
* composite the value can be retrieved with the property or the aliases
*/
@SuppressWarnings("deprecation")
@Test
public void testCompositeProperty() {
Metadata meta = new Metadata();
Property compositeProperty = Property.composite(
DublinCore.DESCRIPTION, new Property[] {
TikaCoreProperties.DESCRIPTION,
Property.internalText("testDescriptionAlt")
});
String message = "composite description";
meta.set(compositeProperty, message);
// Fetch as the composite
assertEquals(message, meta.get(compositeProperty));
// Fetch as the primary property on the composite
assertEquals(message, meta.get(DublinCore.DESCRIPTION));
// Fetch as the aliases
assertEquals(message, meta.get("testDescriptionAlt"));
}
代码示例来源:origin: apache/tika
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
Property prop = getProperty(uri, localName);
if (prop != null) {
if (prop.isMultiValuePermitted()) {
metadata.add(prop, buffer.toString());
} else {
metadata.set(prop, buffer.toString());
}
}
buffer.setLength(0);
}
代码示例来源:origin: apache/tika
private void addMetadata(Metadata metadata, Property property, String value) {
if (value != null) {
String decoded = decode(value);
if (property.isMultiValuePermitted() || metadata.get(property) == null) {
metadata.add(property, decoded);
}
//silently skip adding property that already exists if multiple values are not permitted
}
}
代码示例来源:origin: apache/tika
public void testAdd() {
String[] values = null;
Metadata meta = new Metadata();
values = meta.getValues(CONTENTTYPE);
assertEquals(0, values.length);
meta.add(CONTENTTYPE, "value1");
values = meta.getValues(CONTENTTYPE);
assertEquals(1, values.length);
assertEquals("value1", values[2]);
Property nonMultiValued = Property.internalText("nonMultiValued");
meta.add(nonMultiValued, "value1");
try {
代码示例来源:origin: apache/tika
if (metadata == null || metadata.names() == null) {
return commandMetadataSegments;
for (String metadataName : metadata.names()) {
for (Property property : getMetadataCommandArguments().keySet()) {
if (metadataName.equals(property.getName())) {
String[] metadataCommandArguments = getMetadataCommandArguments().get(property);
if (metadataCommandArguments != null) {
for (String metadataCommandArgument : metadataCommandArguments) {
if (metadata.isMultiValued(metadataName)) {
for (String metadataValue : metadata.getValues(metadataName)) {
String assignmentValue = metadataValue;
代码示例来源:origin: apache/tika
throw new NullPointerException("property must not be null");
if (property.getPropertyType() == PropertyType.COMPOSITE) {
add(property.getPrimaryProperty(), value);
if (property.getSecondaryExtractProperties() != null) {
for (Property secondaryExtractProperty : property.getSecondaryExtractProperties()) {
add(secondaryExtractProperty, value);
String[] values = metadata.get(property.getName());
set(property, value);
} else {
if (property.isMultiValuePermitted()) {
set(property, appendedValues(values, value));
} else {
throw new PropertyTypeException(property.getName() +
" : " + property.getPropertyType());
代码示例来源:origin: apache/tika
for (String n : lastMetadata.names()) {
if (n.equals(ParserUtils.EMBEDDED_PARSER.getName())) continue;
if (n.equals(ParserUtils.EMBEDDED_EXCEPTION.getName())) continue;
String[] newVals = newMetadata.getValues(n);
String[] oldVals = lastMetadata.getValues(n);
if (newVals == null || newVals.length == 0) {
代码示例来源:origin: apache/tika
@Override
protected void addMetadata(String value) {
LOG.trace("adding {}={}", name, value);
if (targetProperty != null && targetProperty.isMultiValuePermitted()) {
if ((value != null && value.length() > 0) || allowEmptyValues) {
if (value == null || value.length() == 0 && allowEmptyValues) {
value = "";
}
String[] previous = metadata.getValues(name);
if (previous == null || !Arrays.asList(previous).contains(value) || allowDuplicateValues) {
metadata.add(targetProperty, value);
}
}
} else {
super.addMetadata(value);
}
}
}
代码示例来源:origin: apache/tika
for (String lang : schema.getLanguagePropertyLanguages(property.getName())) {
String value = schema.getLanguageProperty(property.getName(), lang);
if (!property.isMultiValuePermitted()) {
return;
if (!property.isMultiValuePermitted()) {
if (metadata.get(property) != null) {
return;
代码示例来源:origin: apache/tika
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
metadata.set(Metadata.CONTENT_TYPE, "audio/mpeg");
metadata.set(XMPDM.AUDIO_COMPRESSOR, "MP3");
metadata.set(XMPDM.DURATION, audioAndTags.duration);
metadata.add(XMPDM.LOG_COMMENT.getName(), cmt.toString());
代码示例来源:origin: org.apache.tika/tika-core
/**
* Add a metadata property/value mapping. Add the specified value to the list of
* values associated to the specified metadata property.
*
* @param property
* the metadata property.
* @param value
* the metadata value.
*/
public void add(final Property property, final String value) {
String[] values = metadata.get(property.getName());
if (values == null) {
set(property, value);
} else {
if (property.isMultiValuePermitted()) {
set(property, appendedValues(values, value));
} else {
throw new PropertyTypeException(property.getName() +
" : " + property.getPropertyType());
}
}
}
代码示例来源:origin: apache/tika
/**
* Returns the value (if any) of the identified metadata property.
*
* @since Apache Tika 0.7
* @param property property definition
* @return property value, or <code>null</code> if the property is not set
*/
public String get(Property property) {
return get(property.getName());
}
代码示例来源:origin: apache/tika
@Test
public void testGetField_Author_JSON_Partial_Found() throws Exception {
InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC);
Response response = WebClient.create(endPoint + META_PATH + "/"+TikaCoreProperties.CREATOR.getName())
.type("application/msword")
.accept(MediaType.APPLICATION_JSON).put(copy(stream, 12000));
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Metadata metadata = JsonMetadata.fromJson(new InputStreamReader(
(InputStream) response.getEntity(), UTF_8));
assertEquals("Maxim Valyanskiy", metadata.get(TikaCoreProperties.CREATOR));
assertEquals(1, metadata.names().length);
}
代码示例来源:origin: apache/tika
private void description(Metadata metadata, String prefix, String uri)
throws SAXException {
int count = 0;
for (Property property : Property.getProperties(prefix)) {
String value = metadata.get(property);
if (value != null) {
if (count++ == 0) {
startDescription("", prefix, uri);
}
property(property.getName().substring(prefix.length() + 1), value);
}
}
if (count > 0) {
endDescription();
}
}
内容来源于网络,如有侵权,请联系作者删除!