meta_oxide 0.1.0

Universal metadata extraction library supporting 13 formats (HTML Meta, Open Graph, Twitter Cards, JSON-LD, Microdata, Microformats, RDFa, Dublin Core, Web App Manifest, oEmbed, rel-links, Images, SEO) with 7 language bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# MetaOxide Java Bindings

[![Maven Central](https://img.shields.io/maven-central/v/io.github.yfedoseev/meta-oxide.svg)](https://search.maven.org/artifact/io.github.yfedoseev/meta-oxide)
[![License: MIT OR Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](../../LICENSE)
[![Java](https://img.shields.io/badge/Java-8%2B-orange.svg)](https://www.oracle.com/java/)

Fast, comprehensive metadata extraction for Java - powered by Rust performance with a simple Java API.

## Features

- **Fast**: Native Rust performance (10-100x faster than pure-Java parsers)
- **Comprehensive**: Extracts 13 metadata formats including Open Graph, Twitter Cards, JSON-LD, Microdata, RDFa, Microformats, and more
- **Easy to use**: Simple, idiomatic Java API
- **Thread-safe**: Concurrent extraction supported
- **Zero external dependencies**: Self-contained native library
- **Cross-platform**: Works on Linux, macOS, Windows
- **Java 8+**: Compatible with Java 8 through 21+
- **Android Ready**: Works on Android API 21+

## Supported Formats

MetaOxide extracts **13 metadata formats**:

| Format | Adoption | Use Case |
|--------|----------|----------|
| **Standard Meta Tags** | 100% | Title, description, keywords, canonical |
| **Open Graph** | 60%+ | Facebook, LinkedIn, WhatsApp previews |
| **Twitter Cards** | 45% | Twitter/X link previews |
| **JSON-LD** | 41% ↗️ | Google Rich Results, Schema.org, AI training |
| **Microdata** | 26% | E-commerce, recipes, reviews |
| **RDFa** | 62%* | Semantic web, government sites |
| **Microformats** | 5-10% | IndieWeb (h-card, h-entry, h-event, etc.) |
| **Web App Manifest** | Growing | Progressive Web Apps |
| **Dublin Core** | <5% | Academic, library metadata |
| **oEmbed** | Moderate | YouTube, Twitter embeds |
| **rel-* Links** | Common | Canonical, alternate, feed |

_*62% adoption on desktop pages (HTTP Archive 2024)_

## Installation

### Maven

Add to your `pom.xml`:

```xml
<dependency>
    <groupId>io.github.yfedoseev</groupId>
    <artifactId>meta-oxide</artifactId>
    <version>0.1.0</version>
</dependency>
```

### Gradle

Add to your `build.gradle`:

```groovy
dependencies {
    implementation 'io.github.yfedoseev:meta-oxide:0.1.0'
}
```

### Android

Add to your `build.gradle` (app module):

```groovy
dependencies {
    implementation 'io.github.yfedoseev:meta-oxide:0.1.0'
}
```

**Note**: Native libraries for Android architectures (armeabi-v7a, arm64-v8a, x86, x86_64) are included.

## Quick Start

### Extract All Metadata (Recommended!)

The most efficient way to extract metadata - parses HTML only once:

```java
import io.github.yfedoseev.metaoxide.Extractor;
import io.github.yfedoseev.metaoxide.ExtractionResult;

String html = """
    <html>
    <head>
        <title>Amazing Article</title>
        <meta property="og:title" content="Amazing Article">
        <meta name="twitter:card" content="summary_large_image">
        <script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Article",
            "headline": "Amazing Article"
        }
        </script>
    </head>
    </html>
    """;

ExtractionResult result = Extractor.extractAll(html, "https://example.com");

// Access all formats
System.out.println("Title: " + result.meta.get("title"));
System.out.println("OG Title: " + result.openGraph.get("title"));
System.out.println("Twitter Card: " + result.twitter.get("card"));
System.out.println("JSON-LD: " + result.jsonLd.get(0));
```

### Extract Individual Formats

Extract specific formats when you only need certain metadata:

```java
import java.util.Map;
import java.util.List;

// Standard meta tags
Map<String, Object> meta = Extractor.extractMeta(html, "https://example.com");
System.out.println("Title: " + meta.get("title"));
System.out.println("Description: " + meta.get("description"));

// Open Graph
Map<String, Object> og = Extractor.extractOpenGraph(html, "https://example.com");
System.out.println("OG Title: " + og.get("title"));
System.out.println("OG Image: " + og.get("image"));

// Twitter Cards
Map<String, Object> twitter = Extractor.extractTwitter(html, "https://example.com");
System.out.println("Card Type: " + twitter.get("card"));

// JSON-LD (Schema.org)
List<Object> jsonLd = Extractor.extractJsonLd(html, "https://example.com");
for (Object item : jsonLd) {
    Map<String, Object> obj = (Map<String, Object>) item;
    System.out.println("Type: " + obj.get("@type"));
}

// Microdata
List<Object> microdata = Extractor.extractMicrodata(html, "https://example.com");

// Microformats (h-card, h-entry, h-event, etc.)
Map<String, Object> microformats = Extractor.extractMicroformats(html, "https://example.com");

// RDFa
List<Object> rdfa = Extractor.extractRdfa(html, "https://example.com");

// Dublin Core
Map<String, Object> dublinCore = Extractor.extractDublinCore(html);

// Web App Manifest
Map<String, Object> manifest = Extractor.extractManifest(html, "https://example.com");

// oEmbed
Map<String, Object> oembed = Extractor.extractOembed(html, "https://example.com");

// rel-* links
Map<String, Object> relLinks = Extractor.extractRelLinks(html, "https://example.com");
```

## Examples

### Extract from URL

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

String url = "https://example.com/article";

// Fetch HTML
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create(url))
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

// Extract metadata
ExtractionResult result = Extractor.extractAll(response.body(), url);
System.out.println("Title: " + result.meta.get("title"));
```

### Blog Post Extraction

```java
String html = """
    <article class="h-entry">
        <h1 class="p-name">Getting Started with Rust</h1>
        <time class="dt-published" datetime="2024-01-15">January 15, 2024</time>
        <div class="p-author h-card">
            <span class="p-name">John Smith</span>
        </div>
        <div class="e-content">
            <p>Rust is a systems programming language...</p>
        </div>
    </article>
    """;

Map<String, Object> microformats = Extractor.extractMicroformats(html, "https://example.com");

if (microformats.containsKey("h-entry")) {
    List<Map<String, Object>> entries = (List<Map<String, Object>>) microformats.get("h-entry");
    for (Map<String, Object> entry : entries) {
        System.out.println("Title: " + entry.get("name"));
        System.out.println("Published: " + entry.get("published"));
    }
}
```

### E-commerce Product Extraction

```java
String html = """
    <div itemscope itemtype="https://schema.org/Product">
        <span itemprop="name">Awesome Widget</span>
        <span itemprop="brand">ACME Corp</span>
        <span itemprop="price">29.99</span>
        <div itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
            <span itemprop="ratingValue">4.5</span>
            <span itemprop="reviewCount">127</span>
        </div>
    </div>
    """;

List<Object> microdata = Extractor.extractMicrodata(html, "https://example.com");

for (Object item : microdata) {
    Map<String, Object> product = (Map<String, Object>) item;
    System.out.println("Type: " + product.get("type"));

    Map<String, Object> props = (Map<String, Object>) product.get("properties");
    System.out.println("Name: " + props.get("name"));
    System.out.println("Price: " + props.get("price"));
}
```

### Social Media Preview

```java
String html = """
    <head>
        <meta property="og:title" content="10 Tips for Better Code">
        <meta property="og:description" content="Learn how to write cleaner code">
        <meta property="og:image" content="https://example.com/preview.jpg">
        <meta property="og:url" content="https://example.com/article">

        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="10 Tips for Better Code">
    </head>
    """;

ExtractionResult result = Extractor.extractAll(html, "https://example.com");

// Generate social media preview
System.out.println("Preview Title: " + result.openGraph.get("title"));
System.out.println("Preview Image: " + result.openGraph.get("image"));
System.out.println("Twitter Card: " + result.twitter.get("card"));
```

### Error Handling

```java
import io.github.yfedoseev.metaoxide.MetaOxideException;

try {
    ExtractionResult result = Extractor.extractAll(html, "https://example.com");
    // Process result
} catch (MetaOxideException e) {
    System.err.println("Error extracting metadata: " + e.getMessage());
    System.err.println("Error code: " + e.getErrorCode());
    e.printStackTrace();
}
```

### Thread Safety

All methods are thread-safe and can be called concurrently:

```java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

ExecutorService executor = Executors.newFixedThreadPool(10);

List<String> urls = Arrays.asList(
    "https://example1.com",
    "https://example2.com",
    "https://example3.com"
);

for (String url : urls) {
    executor.submit(() -> {
        try {
            String html = fetchHtml(url);
            ExtractionResult result = Extractor.extractAll(html, url);
            System.out.println(url + ": " + result.meta.get("title"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}

executor.shutdown();
```

## API Reference

### Extractor Class

Main API class with static methods for extraction.

#### extractAll(String html, String baseUrl)

Extract all metadata formats at once (most efficient).

**Parameters:**
- `html` (String) - HTML content (required)
- `baseUrl` (String) - Base URL for resolving relative URLs (optional)

**Returns:** `ExtractionResult` containing all metadata formats

**Throws:** `MetaOxideException` on error

---

#### extractMeta(String html, String baseUrl)

Extract standard HTML meta tags.

**Returns:** `Map<String, Object>` with meta tag properties

---

#### extractOpenGraph(String html, String baseUrl)

Extract Open Graph Protocol metadata.

**Returns:** `Map<String, Object>` with Open Graph properties

---

#### extractTwitter(String html, String baseUrl)

Extract Twitter Cards metadata.

**Returns:** `Map<String, Object>` with Twitter Card properties

---

#### extractJsonLd(String html, String baseUrl)

Extract JSON-LD structured data.

**Returns:** `List<Object>` of JSON-LD objects

---

#### extractMicrodata(String html, String baseUrl)

Extract Microdata.

**Returns:** `List<Object>` of Microdata items

---

#### extractMicroformats(String html, String baseUrl)

Extract Microformats (h-card, h-entry, h-event, etc.).

**Returns:** `Map<String, Object>` of Microformats by type

---

#### extractRdfa(String html, String baseUrl)

Extract RDFa structured data.

**Returns:** `List<Object>` of RDFa items

---

#### extractDublinCore(String html)

Extract Dublin Core metadata.

**Returns:** `Map<String, Object>` with Dublin Core properties

---

#### extractManifest(String html, String baseUrl)

Extract Web App Manifest link.

**Returns:** `Map<String, Object>` with manifest information

---

#### parseManifest(String manifestJson, String baseUrl)

Parse Web App Manifest JSON content.

**Parameters:**
- `manifestJson` (String) - Manifest JSON content
- `baseUrl` (String) - Base URL for resolving relative URLs

**Returns:** `Map<String, Object>` with parsed manifest properties

---

#### extractOembed(String html, String baseUrl)

Extract oEmbed endpoint discovery.

**Returns:** `Map<String, Object>` with oEmbed information

---

#### extractRelLinks(String html, String baseUrl)

Extract rel-* link relationships.

**Returns:** `Map<String, Object>` of link relationships by rel type

---

#### getVersion()

Get the MetaOxide library version.

**Returns:** `String` version (e.g., "0.1.0")

---

### ExtractionResult Class

Container for all extracted metadata.

**Fields:**
- `meta` (Map<String, Object>) - Standard HTML meta tags
- `openGraph` (Map<String, Object>) - Open Graph metadata
- `twitter` (Map<String, Object>) - Twitter Cards metadata
- `jsonLd` (List<Object>) - JSON-LD structured data
- `microdata` (List<Object>) - Microdata items
- `microformats` (Map<String, Object>) - Microformats by type
- `rdfa` (List<Object>) - RDFa items
- `dublinCore` (Map<String, Object>) - Dublin Core metadata
- `manifest` (Map<String, Object>) - Web App Manifest
- `oembed` (Map<String, Object>) - oEmbed information
- `relLinks` (Map<String, Object>) - rel-* link relationships

---

### MetaOxideException Class

Exception thrown on extraction errors.

**Methods:**
- `getErrorCode()` - Get error code from native library
- `getMessage()` - Get error message
- `toString()` - String representation including error code

## Performance

MetaOxide is built with Rust for maximum performance:

| HTML Size | Parse + Extract Time | Throughput |
|-----------|---------------------|------------|
| 10 KB     | ~60 µs              | 166 MB/s   |
| 100 KB    | ~600 µs             | 166 MB/s   |
| 1 MB      | ~6 ms               | 166 MB/s   |

*Benchmarks on Intel i7 @ 3.5 GHz*

**10-100x faster** than pure-Java HTML parsers like Jsoup for metadata extraction!

## Building from Source

### Prerequisites

- Java 8 or higher
- Maven 3.6+
- Rust 1.70+ (for building native library)
- C compiler (GCC or Clang)

### Build Steps

```bash
# Clone the repository
git clone https://github.com/yfedoseev/meta-oxide.git
cd meta-oxide/bindings/java/meta-oxide-java

# Build native library (in root directory)
cd ../../../
cargo build --release --features c-api

# Copy native library to resources
mkdir -p bindings/java/meta-oxide-java/src/main/resources/native/linux-x86_64
cp target/release/libmeta_oxide.so bindings/java/meta-oxide-java/src/main/resources/native/linux-x86_64/

# Build Java library
cd bindings/java/meta-oxide-java
mvn clean install

# Run tests
mvn test
```

### Cross-Platform Builds

To build for multiple platforms, use cross-compilation or build on each platform:

**Linux x86_64:**
```bash
cargo build --release --features c-api --target x86_64-unknown-linux-gnu
```

**macOS x86_64:**
```bash
cargo build --release --features c-api --target x86_64-apple-darwin
```

**macOS ARM64:**
```bash
cargo build --release --features c-api --target aarch64-apple-darwin
```

**Windows x86_64:**
```bash
cargo build --release --features c-api --target x86_64-pc-windows-msvc
```

## Android Usage

### Setup

Add to your `build.gradle`:

```groovy
android {
    // ...

    packagingOptions {
        pickFirst 'lib/armeabi-v7a/libmeta_oxide.so'
        pickFirst 'lib/arm64-v8a/libmeta_oxide.so'
        pickFirst 'lib/x86/libmeta_oxide.so'
        pickFirst 'lib/x86_64/libmeta_oxide.so'
    }
}

dependencies {
    implementation 'io.github.yfedoseev:meta-oxide:0.1.0'
}
```

### Example Android Activity

```java
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import io.github.yfedoseev.metaoxide.Extractor;
import io.github.yfedoseev.metaoxide.ExtractionResult;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Extract metadata in background thread
        new Thread(() -> {
            try {
                String html = fetchHtml("https://example.com");
                ExtractionResult result = Extractor.extractAll(html, "https://example.com");

                runOnUiThread(() -> {
                    // Update UI with results
                    titleTextView.setText(result.meta.get("title").toString());
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }
}
```

## Publishing to Maven Central

This package is published to Maven Central. To publish a new version:

1. Configure your `~/.m2/settings.xml` with OSSRH credentials
2. Build and sign the artifacts:

```bash
mvn clean deploy -P release
```

3. The artifacts will be automatically staged and released to Maven Central

## Comparison with Other Libraries

| Feature | MetaOxide | Jsoup | Apache Tika |
|---------|-----------|-------|-------------|
| Speed | ⚡ 10-100x faster | Moderate | Slow |
| Formats | 13 formats | Manual parsing | Limited |
| Open Graph || Manual ||
| JSON-LD || Manual ||
| Microformats | ✅ 9 types |||
| RDFa ||||
| Thread-safe ||||
| Dependencies | Zero | Many | Many |

## Contributing

Contributions are welcome! See the main repository for contribution guidelines.

## License

MetaOxide is dual-licensed under:

- MIT License ([LICENSE-MIT]../../LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE]../../LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)

You may choose either license for your use.

## Links

- **Main Repository**: https://github.com/yfedoseev/meta-oxide
- **Maven Central**: https://search.maven.org/artifact/io.github.yfedoseev/meta-oxide
- **Documentation**: https://github.com/yfedoseev/meta-oxide/tree/main/docs
- **Issue Tracker**: https://github.com/yfedoseev/meta-oxide/issues

## Support

- Open an issue on GitHub
- Check the documentation
- See examples in the `examples/` directory

---

Made with ❤️ and Rust