Package Torello.HTML
Class Features.Meta
- java.lang.Object
-
- Torello.HTML.Features.Meta
-
- Enclosing class:
- Features
public static class Features.Meta extends java.lang.Object
Tools made specifically for the<META>
tags in the<HEAD>
of a web-page.Search Engine Optimization
This class handles some of the extremely common features found on HTML Web-Pages. The collection of capabilities that may be handled by this class are usually referred to as "SEO" or "Search Engine Optimization."
This nested inner class deals, explicitly, with inserting and retrieving HTML <META ...>-Tags into & out-of Web-Pages. This is usually the type of work that falls under the general category called 'SEO', or Search-Engine Optimization.
When comanies like Google employ their Web-Crawlers to scour the Internet for pages to index, they usually start with the any & allMETA
-Tag information that Web-Page Designers have explicity placed into their pages'HEAD'
-Sections. HTML Page Writers use these tags in order to tell companies (like Google, for instance) what they feel is most salient about the pages that they write. This (theoretically) helps Google better select pages for the results returned by their Search-Engine.
Google and other search engines, and even non-search engine companies, individuals or organizations can and will use HTMLMETA
elements in any way they so choose. SomeMETA
-tag information will influence Google's software decisions on what web-sites to return with it's search-results pages to varying degrees of success.
This class also includes some simplification of the 'Open Graph' protocol so that users can also identify their content to anybody who would want to include links to their pages. Open-Graph can be useful to Google, but it is often used to identify which elements of an HTML page should be displayed when someone posts a link to any particular web-page that has open-graph meta-tags in its HTML head section.
For instance, if an Open Graph HTMLMeta
-Tag is added to a Web-Page header that picks a particular HTML picture (<IMG SRC='...'>
element), links to that page will be rendered by any Application that uses Open-Graph showing that very image.
Hi-Lited Source-Code:- View Here: Torello/HTML/Features.java
- Open New Browser-Tab: Torello/HTML/Features.java
File Size: 74,175 Bytes Line Count: 1,528 '\n' Characters Found
Stateless Class:This class neither contains any program-state, nor can it be instantiated. The@StaticFunctional
Annotation may also be called 'The Spaghetti Report'.Static-Functional
classes are, essentially, C-Styled Files, without any constructors or non-static member fields. It is a concept very similar to the Java-Bean's@Stateless
Annotation.
- 1 Constructor(s), 1 declared private, zero-argument constructor
- 24 Method(s), 24 declared static
- 10 Field(s), 10 declared static, 10 declared final
-
-
Field Summary
Fields Modifier and Type Field static String
authorMetaTag
static String
descriptionMetaTag
static String
keyWordsMetaTag
static String
metaTagHTTPEquiv
static String
metaTagItemProp
static String
metaTagName
static String
openGraphMetaTag
static TreeMap<String,String>
openGraphProperties
static String
robotsMetaTag
static String
UTF8MetaTag
-
Method Summary
Retrieve: All HTML Meta-Tags, as a java.util.Properties instance Modifier and Type Method static Vector<Properties>
getAllMeta(Vector<HTMLNode> page)
Retrieve: Meta-Tag's having 'NAME' and 'CONTENT' Attributes Modifier and Type Method static Hashtable<MetaTagName,
String>getAllMetaTagNames(Vector<? extends HTMLNode> html)
static String
getMetaTagName(Vector<HTMLNode> html, String name)
Retrieve: Meta-Tag's having a SPECIFIC NAME-Attribute Modifier and Type Method static String[]
getAllKeyWords(Vector<? extends HTMLNode> html)
static Vector<Robots>
getAllRobots(Vector<? extends HTMLNode> html)
static Vector<Robots>
getAllRobotsNOMHE(Vector<? extends HTMLNode> html)
static String
hasAuthor(Vector<? extends HTMLNode> html)
static String
hasDescription(Vector<? extends HTMLNode> html)
Retrieve: HTTP-Header Meta-Tags (Tags with both 'HTTP-EQUIV' and 'CONTENT' Attributes) Modifier and Type Method static Properties
getAllHTTPEquiv(Vector<HTMLNode> html)
static String
getHTTPEquiv(Vector<HTMLNode> html, String httpEquiv)
static boolean
hasUTF8MetaTag(Vector<? extends HTMLNode> html)
Insert: Meta-Tag's with a NAME-Attribute Modifier and Type Method static void
insertMetaTagName(Vector<HTMLNode> html, MetaTagName m, String contentAttributeValue)
static void
insertMetaTagNames(Vector<HTMLNode> html, Hashtable<MetaTagName,String> metaTags)
Insert: Meta-Tags with SPECIFIC NAME-Attributes Modifier and Type Method static void
insertAuthor(Vector<HTMLNode> html, String author)
static void
insertDescription(Vector<HTMLNode> html, String description)
static void
insertKeyWords(Vector<HTMLNode> html, String... keyWords)
static void
insertRobots(Vector<HTMLNode> html, boolean index, boolean follow)
static void
insertRobots(Vector<HTMLNode> html, Robots... rArr)
Insert: HTTP-Header Meta-Tags (Tags with both 'HTTP-EQUIV' and 'CONTENT' Attributes) Modifier and Type Method static void
insertHTTPEquiv(Vector<HTMLNode> html, String httpEquiv, String contentAttributeValue)
static void
insertUTF8MetaTag(Vector<HTMLNode> html)
Methods: ITEMPROP Meta-Tags Modifier and Type Method static String
getItemProp(Vector<HTMLNode> html, String itemProp)
static void
insertItemProp(Vector<HTMLNode> html, String itemProp, String contentAttributeValue)
Methods: Open-Graph Meta-Tags Modifier and Type Method static Properties
getAllOGMetaTags(Vector<? extends HTMLNode> html)
static void
insertOGMetaTag(Vector<HTMLNode> html, String ogProperty, String ogValueAsStr)
-
-
-
Field Detail
-
metaTagName
public static final java.lang.String metaTagName
This is the most common HTML<META ... >
Tag.- See Also:
getAllMetaTagNames(Vector)
,insertMetaTagName(Vector, MetaTagName, String)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String metaTagName = "<META NAME='INSERT-NAME-STRING-HERE' CONTENT='INSERT-CONTENT-STRING-HERE'>";
-
metaTagItemProp
public static final java.lang.String metaTagItemProp
This HTML<META ...>
Tag is less frequently used, but does provide some properties needed and used by various Web-Servers. It is the'ITEMPROP'
Meta-Tag.- See Also:
getItemProp(Vector, String)
,insertItemProp(Vector, String, String)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String metaTagItemProp = "<META ITEMPROP='INSERT-ITEMPROP-STRING-HERE' CONTENT='INSERT-CONTENT-STRING-HERE'>";
-
metaTagHTTPEquiv
public static final java.lang.String metaTagHTTPEquiv
ThisString
can be placed in an HTML-Page's <HEAD> ... </HEAD> section in order to insert an HTTP-Equivalent Meta-Tag directive into your page.HTTP-EQUIV
-Tags are just tags that can be used in place of (as a substitute for)HTTP
-Properties which would under otherwise normal circumstances be transmitted / communicated directly by the Web-Server using the Web-Response Header itself. InsertingHTTP-EQUIV
Meta-Tags onto a page alleviates the need for configuring Web-Server responses, and allows the HTML-Devloper to have some control of the Client-Server interaction.
Below are some (very common)HTTP
-Header Properties, followed by theHTTP-EQUIV
Meta-Tags that may be used to simulate theHTTP
-Header with Meta-Tag's place into theHEAD
-Section of a Web-Page.HTTP
-Header PropertyHTTP-EQUIV
Web-Page Meta-TagContent-Type: text/html; charset=UTF-8 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> Cache-Control:public, max-age=0 <META HTTP-EQUIV="Cache-Control" CONTENT="public, max-age=0" Refresh: 30 <META HTTP-EQUIV="Refresh" CONTENT="30"
An HTML Meta-Tag is built using an Attribute-value pair whose Attribute-name is'HTTP-EQUIV'
, and whose value is any one of the commonHTTP
-Properties which Web-Servers Transmit.
The value of theHTTP
-Property is stored in the Meta-Tag'sCONTENT
-Attribute.- See Also:
getHTTPEquiv(Vector, String)
,insertHTTPEquiv(Vector, String, String)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String metaTagHTTPEquiv = "<META HTTP-EQUIV='INSERT-HTTP-EQUIV-STRING-HERE' CONTENT='INSERT-CONTENT-STRING-HERE'>";
-
robotsMetaTag
public static final java.lang.String robotsMetaTag
ThisString
can be placed in an HTML-Page's <HEAD> ... </HEAD> section in order to insert arobots
-Property Meta-Tag onto your page.
A Meta-Property is an HTML Meta-Tag with an Attribute-value pair whose Attribute-name is (actually)'NAME'
, and whose value is the property's name, which here would be'robots'
.
The value of the Meta-Property is specified by the value of that Tag'sCONTENT
-Attribute.
ARobots
-Property Meta-Tag lets you utilize a granular, page-specific approach to controlling how an individual page should be indexed and served to users in Search-Engine results.- See Also:
insertRobots(Vector, boolean, boolean)
,getAllRobots(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String robotsMetaTag = "<META NAME=robots CONTENT='INSERT-CONTENT-STRING-HERE'>";
-
descriptionMetaTag
public static final java.lang.String descriptionMetaTag
ThisString
can be placed in an HTML-Page's <HEAD> ... </HEAD> section in order to insert adescription
-Property Meta-Tag onto your page.
A Meta-Property is an HTML Meta-Tag with an Attribute-value pair whose Attribute-name is (actually)'NAME'
, and whose value is the property's name, which here would be'description'
.
The value of the Meta-Property is specified by the value of that Tag'sCONTENT
-Attribute.
When search engines crawl Internet Web-Pages to read the provided key-words and descriptions used for indexing, this particular Meta-Tag Property is one of the first those crawlers will look at.
You may include aDescription
-Property in the'HEAD'
portion of your site’s main-page. AMETA
-Description can influence both a Search-Engine's Web-Crawlers, and ultimately the click-through rates of your readers.
Google has stated that Meta-TagDescription
-Properties are NOT used to rank pages.- See Also:
insertDescription(Vector, String)
,hasDescription(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String descriptionMetaTag = "<META NAME=description CONTENT='INSERT-DESCRIPTION-OR-KEYWORDS-HERE'>";
-
UTF8MetaTag
public static final java.lang.String UTF8MetaTag
This was actually the most used HTMLMETA
-Tag element used on both the Spanish News Board, and the Chinese News Board websites. When thisMETA
-Tag is included on a Web-Page, it guarantees that the Web-Browser will make every effort to use and accommodateUTF-8
-Characters.
This is an'HTTP-EQUIV'
Meta-Tag, meaning that the function it performs could also be accomplished by configuring your Web-Server to insert aContent-Type: text/html; charset=utf-8
directive into theHTTP
-Header whenever it receives a request for the particular pages which use theUTF-8
Character-Set.
Foreign Language Characters:
As an aside, when working with strictly-English pages, theASCII
Character-Set (which are the first 256 characters of theUTF-8
Character-Set) should suffice. However, using theUTF-8
Character-Set allows for language characters from just about any language on the planet.
My experience, thus far, has been that when theString
below is inserted into an HTML Web-Page, the receiving Web-Browser is guaranteed to serve up content in just about any language.HTTP-EQUIV
Directive:
Since this is anHTTP-EQUIV
-Directive Meta-Tag, this does mean that the same results may be achieved by configuring your Web-Server or Web-Hosting Company to serve up your page(s) using the exact sameHTTP
-Property. In Google Cloud Platform's "Storage Buckets" - assigning theHTTP
-PropetyContent-Type: text/html; charset=UTF-8
is easily done using a few clicks of the mouse or the command line tool GSUTIL.
Either way, or both, Web-Browser should work just fine when rendering language characters in Mandarin, Korean, Spanish, Russian, Japanese, Arabic, etc...你好,世界! こんにちは世界! 안녕, 세상! ¡Hola Mundo! مرحبا بالعالم! Hello World!
Alternative Meta-Tag Option:
ACCORDING TO: Popular website'http://www.w3schools.com'
, the following is true about setting the char-set for a web-site using HTML'meta'
tags:Differences Between HTML 4.01 and HTML5:
Using http-equiv is no longer the only way to specify the character set of an HTML document:- HTML 4.01:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
- HTML5:
<meta charset="UTF-8">
- See Also:
insertUTF8MetaTag(Vector)
,hasUTF8MetaTag(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String UTF8MetaTag = "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>";
- HTML 4.01:
-
openGraphMetaTag
public static final java.lang.String openGraphMetaTag
The following content was copied from: http://ogp.me, the primary Open-Graph Protocol Website. It was word-for-word text-lifted on May 25th, 2019.Introduction
The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
While many different technologies and schema exist and could be combined together, there isn't a single technology which provides enough information to richly represent any web page within the social graph. The Open Graph protocol builds on these existing technologies and gives developers one thing to implement. Developer simplicity is a key goal of the Open Graph protocol which has informed many of the technical design decisions.
Basic Metadata
To turn your web pages into graph objects, you need to add basic metadata to your page. We've based the initial version of the protocol on RDFa which means that you'll place additional<meta>
tags in the<head>
of your web page. The four required properties for every page are:
og:title
- The title of your object as it should appear within the graph, e.g., "The Rock".og:type
- The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.og:image
- An image URL which should represent your object within the graph.og:url
- The canonical URL of your object that will be used as its permanent ID in the graph, e.g., "http://www.imdb.com/title/tt0117500/"
Optional Metadata
The following properties are optional for any object and are generally recommended:
og:audio
- A URL to an audio file to accompany this object.og:description
- A one to two sentence description of your object.og:determiner
- The word that appears before this object's title in a sentence. An enum of (a, an, the, "", auto). If auto is chosen, the consumer of your data should chose between "a" or "an". Default is "" (blank).og:locale
- The locale these tags are marked up in. Of the format language_TERRITORY. Default is en_US.og:locale:alternate
- An array of other locales this page is available in.og:site_name
- If your object is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb".og:video
- A URL to a video file that complements this object.
Structured Properties
Some properties can have extra metadata attached to them. These are specified in the same way as other metadata with property and content, but the property will have extra :.
The og:image property has some optional structured properties:
og:image:url
- Identical to og:image.og:image:secure_url
- An alternate url to use if the webpage requires HTTPS.og:image:type
- A MIME type for this image.og:image:width
- The number of pixels wide.og:image:height
- The number of pixels high.og:image:alt
- A description of what is in the image (not a caption). If the page specifies an og:image it should specify og:image:alt.
Video
Namespace URI: http://ogp.me/ns/video#og:type
values:
video.movie
video:actor
- profile array - Actors in the movie.video:actor:role
- string - The role they played.video:director
- profile array - Directors of the movie.video:writer
- profile array - Writers of the movie.video:duration
- integer >=1 - The movie's length in seconds.video:release_date
- datetime - The date the movie was released.video:tag
- string array - Tag words associated with this movie.
video.episode
video:actor
- Identical to video.movievideo:actor:role
video:director
video:writer
video:duration
video:release_date
video:tag
video:series - video.tv_show
- Which series this episode belongs to.
Music
Namespace URI: http://ogp.me/ns/music#og:type values:
music.song
music:duration
- integer >=1 - The song's length in seconds.music:album
- music.album array - The album this song is from.music:album:disc
- integer >=1 - Which disc of the album this song is on.music:album:track
- integer >=1 - Which track this song is.music:musician
- profile array - The musician that made this song.
music.album
music:song
- music.song - The song on this album.music:song:disc
- integer >=1 - The same as music:album:disc but in reverse.music:song:track
- integer >=1 - The same as music:album:track but in reverse.music:musician
- profile - The musician that made this song.music:release_date
- datetime - The date the album was released.
music.playlist
music:song
- Identical to the ones on music.albummusic:song:disc
music:song:track
music:creator
- profile - The creator of this playlist.
music.radio_station
music:creator
- profile - The creator of this station.
No Vertical
These are globally defined objects that just don't fit into a vertical but yet are broadly used and agreed upon.
og:type
values:
article
- Namespace URI: http://ogp.me/ns/article#article:published_time
- datetime - When the article was first published.article:modified_time
- datetime - When the article was last changed.article:expiration_time
- datetime - When the article is out of date after.article:author
- profile array - Writers of the article.article:section
- string - A high-level section name. E.g. Technologyarticle:tag
- string array - Tag words associated with this article.
book
- Namespace URI: http://ogp.me/ns/book#book:author
- profile array - Who wrote this book.book:isbn
- string - The ISBNbook:release_date
- datetime - The date the book was released.book:tag
- string array - Tag words associated with this book.
profile
- Namespace URI: http://ogp.me/ns/profile#profile:first_name
- string - A name normally given to an individual by a parent or self-chosen.profile:last_name
- string - A name inherited from a family or marriage and by which the individual is commonly known.profile:username
- string - A short unique string to identify them.profile:gender
- enum(male, female) - Their gender.
website
- Namespace URI: http://ogp.me/ns/website#
No additional properties other than the basic ones. Any non-marked up webpage should be treated as og:type website.
Types
The following types are used when defining attributes in Open Graph protocol.Type Description Literals Boolean A Boolean represents a true or false value true, false, 1, 0 DateTime A DateTime represents a temporal value composed of a date (year, month, day) and an optional time component (hours, minutes) https://en.wikipedia.org/w/index.php?title=ISO_8601&oldid=898205005 Enum A type consisting of bounded set of constant string values (enumeration members). A string value that is a member of the enumeration Float A 64-bit signed floating point number All literals that conform to the following formats:
1.234
-1.234
1.2e3
-1.2e3
7E-10
Integer A 32-bit signed integer. In many languages integers over 32-bits become floats, so we limit Open Graph protocol for easy multi-language use. All literals that conform to the following formats:
1234
-123
String A sequence of Unicode characters All literals composed of Unicode characters with no escape characters URL A sequence of Unicode characters that identify an Internet resource. All valid URLs that utilize the http:// or https:// protocols
- See Also:
insertOGMetaTag(Vector, String, String)
,getAllOGMetaTags(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String openGraphMetaTag = "<META PROPERTY='og:INSERT-OG-PROPERTY-HERE' CONTENT='INSERT-OG-VALUE-HERE'>";
-
openGraphProperties
public static final java.util.TreeMap<java.lang.String,java.lang.String> openGraphProperties
All Open-Graph Property names.
-
keyWordsMetaTag
public static final java.lang.String keyWordsMetaTag
ThisString
can be placed in an HTML-Page's <HEAD> ... </HEAD> section in order to insert akeywords
-Property Meta-Tag onto your page.
A Meta-Property is an HTML Meta-Tag with an Attribute-value pair whose Attribute-name is (actually)'NAME'
, and whose value is the property's name, which here would be'keywords'
.
The value of the Meta-Property is specified by the value of that Tag'sCONTENT
-Attribute.
AKeyWords
-Property helps identify relevant, pertinent or 'germane' words that describe the content of a Web-Site or Web-Page to a Web-Indexing or Web-Search Organization.- See Also:
insertKeyWords(Vector, String[])
,getAllKeyWords(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String keyWordsMetaTag = "<META NAME=keywords CONTENT='INSERT-COMMA-SEPARATED-KEYWORDS-HERE'>";
-
authorMetaTag
public static final java.lang.String authorMetaTag
ThisString
can be placed in an HTML-Page's <HEAD> ... </HEAD> section in order to insert aauthor
-Property Meta-Tag onto your page.
A Meta-Property is an HTML Meta-Tag with an Attribute-value pair whose Attribute-name is (actually)'NAME'
, and whose value is the property's name, which here would be'author'
.
The value of the Meta-Property is specified by the value of that Tag'sCONTENT
-Attribute.
This helps identify Web-Sites or Web-Pages "Author-Names" to Web-Indexing and Web-Search Organizations.- See Also:
insertAuthor(Vector, String)
,hasAuthor(Vector)
, Constant Field Values- Code:
- Exact Field Declaration Expression:
public static final String authorMetaTag = "<META NAME=author CONTENT='INSERT-AUTHOR-NAME-HERE'>";
-
-
Method Detail
-
getAllMeta
public static java.util.Vector<java.util.Properties> getAllMeta (java.util.Vector<HTMLNode> page)
This simple method will retrieve ajava.util.Properties
object for each and every HTML<META ...>
tag found within a Vectorized-HTML Web-Page.- Parameters:
page
- Any Vectorized-HTML page. It is expected that this page contain a fewMETA
-Tags. If not, the method will still return an emptyVector<Properties>
havingsize()
of zero.- Returns:
- The Java
'Properties'
object that is returned from a call toTagNode.allAV()
- See Also:
TagNode.allAV()
,TagNodeGet
- Code:
- Exact Method Body:
Vector<Properties> ret = new Vector<>(); // Retrieve all TagNode's that are HTML <META ...> Elements. Invoke TagNode.allAV() // on each of these nodes to retrieve a java.util.Properties instance.\ // // NOTE: These "Properties" could possibly be combined into a single Properties // instance, but because of the ever-changing nature of Web-Page // Meta-Information tags, this is not employed here. It is an exercise // left to the programmer. for (TagNode tn : TagNodeGet.all(page, TC.OpeningTags, "META")) ret.add(tn.allAV()); return ret;
-
getMetaTagName
public static java.lang.String getMetaTagName (java.util.Vector<HTMLNode> html, java.lang.String name)
This method will find an HTML<META NAME=... CONTENT=...>
element whoseNAME
-Attribute has aString
-value equal-to (ignoring case) the value of the providedString
-parameter'name'
.
After this HTMLMETA
-Tag has been identified, theString
-value of it'sCONTENT
-Attribute will be extracted and returned.
Returning null, Gracefully:
If the page provided does not have an HTML Meta-Tag with aNAME
-Attribute whose value is'name'
or if such an element is identified, but that tag does not have aCONTENT
-Attribute, then this method will return null.
Case Insensitive Comparison:
Before the comparison is done with the'name'
parameter, thatString
is trimmed withString.trim()
, and the comparison performed is done while ignoring case.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.name
- The name of the<META NAME=...>
Tag.- Returns:
- The
String
-value of theCONTENT
-Attribute for a Meta-Tag whoseNAME
-Attribute is equal to the specified name provided by parameter'name'
. If such information is not found on the page, then this method shall return null. - See Also:
getItemProp(Vector, String)
,getHTTPEquiv(Vector, String)
- Code:
- Exact Method Body:
// Find the first <META NAME=... CONTENT=...> tag element where the name equals // the string-value provided by parameter name. TagNode tn = InnerTagGet.first (html, "META", "NAME", TextComparitor.EQ_CI, name.trim()); // If there are no <META NAME='NAME' CONTENT=...> elements found on the page, // then this method returns null. if (tn == null) return null; // Return the string-value of the attribute 'content'. Note that if this // attribute isn't available, this method shall return 'null', gracefully. return tn.AV("CONTENT");
-
getAllMetaTagNames
public static java.util.Hashtable<MetaTagName,java.lang.String> getAllMetaTagNames (java.util.Vector<? extends HTMLNode> html)
This will retrieve all Meta-Tag's havingNAME
-Attribute andCONTENT
-Attribute pairs.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- a
java.util.Hashtable
of all the Meta-Tag Name/Content pairs that do not have null values. - Throws:
java.lang.IllegalArgumentException
- The methodMetaTagName.valueOf(...)
will throw an Illegal Argument Exception if any of the<META NAME=...>
elements use a value of "NAME" that is not listed or identified in the Enumerated Type "MetaTagName".
ALTERNATIVE: As Internet Companies come and go, pinning down a complete list of valid Meta Tag's that use the "NAME" Attribute is a possibly misguided approach. In lieu of eliminating the Enumerated-TypeMetaTagName
, it should be easier to just use the standard TagNode search below:
Example:
// This code should be used as an alternative to this method if there are non-standard // HTML Meta Tag Names. It uses the more fundamental InnerTagGet Method. // This will retrieve all <META ...> HTML Elements that have a "NAME" Property. Vector<TagNode> metaTags = InnerTagGet.all(page, "meta", "name"); // This will print out those results: for (TagNode metaTag : metaTags) System.out.println ("Name:\t" + metaTag.AV("name") + "\tContent:\t" + metaTag.AV("content"));
- See Also:
MetaTagName
,metaTagName
,insertMetaTagName(Vector, MetaTagName, String)
,InnerTagGet
- Code:
- Exact Method Body:
Hashtable<MetaTagName, String> ret = new Hashtable<>(); // Converting the output "Vector<TagNode>" to a "Stream<TagNode>" by calling the // .stream() method mainly because java streams provide the very simple // 'filter(Predicate)' and 'forEach(Consumer)' methods. Vector.removeIf and // Vector.forEach could also have been easily used as well. // InnerTagGet.all returns a vector containing all <META NAME=...> TagNode's where // the value of the 'name' attribute is one of the pre-defined MetaTagName // EnumeratedTypes. // NOTE: This is done via a java.util.function.Predicate<String> and a lambda // expression InnerTagGet .all (html, "META", "NAME", (String nameAttributeValue) -> MetaTagName.valueOf (nameAttributeValue.toLowerCase().trim()) != null) .stream() .filter((TagNode tn) -> tn.AV("CONTENT") != null) .forEach((TagNode tn) -> ret.put( MetaTagName.valueOf(tn.AV("NAME").toLowerCase().trim()), tn.AV("CONTENT") )); return ret;
-
getAllRobots
public static java.util.Vector<Robots> getAllRobots (java.util.Vector<? extends HTMLNode> html) throws MalformedHTMLException
This method looks for robots HTML<META NAME=robots>
tag, and returns the value of thecontent
-Attribute.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- This will return a vector of the robots named or specified by the HTML
Meta-Tag's present on this page.
NOTE: Please do not be disturbed by java-streams, they are of limited use, but once a programmer is accustomed to the words above, they actually improve code-readability (once in a while!). A series of simplefor-loops
which eliminate-duplicates / add / sort would accomplish the same task as above. - Throws:
MalformedHTMLException
- If any invalid robot-strings are found on the page, this method will throw an exception. The impetus behind this is to prevent accidentally ignoring newly found tags, or incorrect tags. The extraction of the robots Meta-Tag from an HTML page can be performed manually, if throwing an exception is causing problems. The code to do this is listed in the documentation of this method.- See Also:
robotsMetaTag
,insertRobots(Vector, boolean, boolean)
- Code:
- Exact Method Body:
// Here, again, using Java Streams can be sometimes useful - primarily whenever a // 'filter' operation is going to be used on a Vector. Vector.removeIf works, BUT // this also extracts attribute values, and the original TagNode are discarded, and // replaced by the the <META> attributes. // // ALSO SALIENT: the "Arrays.asList" produces an array of string, and the "::addAll" // puts each separate String in each array into the TreeSet. // // NOTE: The TreeSet also functions as a "duplicate checker" although this is also // provided by Stream.distinct() // // InnerTagGet.all; Returns a vector of TagNode's that resemble: // <META NAME="robots" ...> // // EQ_CI_TRM: Check the 'name' Attribute-Value using a Case-Insensitive, Equality // String-Comparison // Trim the 'name' Attribute-Value String of possible leading & trailing // White-Space before performing the comparison. TreeSet<String> temp = InnerTagGet .all (html, "META", "NAME", TextComparitor.EQ_CI_TRM, "robots") .stream () .map ((TagNode tn) -> tn.AV("CONTENT")) .filter ((String contents) -> (contents != null) && (contents.trim().length() > 0)) .map ((String contents) -> Arrays.asList(StrCSV.CSV(contents.toLowerCase()))) .collect (TreeSet<String>::new, TreeSet::addAll, TreeSet::addAll); // I cannot use EXCEPTIONS and STREAMS together, there is no simple way. // It would be too ugly to read. Vector<Robots> ret = new Vector<>(); // If an invalid robot-attribute is found, this will // throw a MalformedHTMLException for (String s : temp) ret.add(Robots.getRobot(s)); return ret;
-
getAllRobotsNOMHE
public static java.util.Vector<Robots> getAllRobotsNOMHE (java.util.Vector<? extends HTMLNode> html)
This will retrieve the'robots'
Meta-Tag Attribute-value present on a Web-Page.
If any of them are not in accordance with the tags listed in the Enumerated-TypeRobots
, this will not cause aMalformedHTMLException
to throw. Instead, the result will just be eliminated and ignored. Take care that all of the necessaryROBOTS
-Tags are listed in the Enumerated-Type, and that there are no "undefined, but necessary" robot elements to be found before using this method!- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- A vector of all the valid robots attribute values found on the web-page.
- See Also:
robotsMetaTag
,insertRobots(Vector, boolean, boolean)
,TagNode.AV(String)
- Code:
- Exact Method Body:
// Java Streams, used here, filter out irrelevant meta tags, and also convert the // HTML Meta TagNode's into their their "CONTENT" Attribute String value. The TreeSet // provides a duplicate check elimination and sorts the {@code String's} as well. // // ALSO SALIENT: the "Arrays.asList" produces an array of string, and the "::addAll" // puts each separate String in each array into the TreeSet // // NOTE: The 'getRobotNOMHE' suppresses a possible exception, and converts such a // situation to 'null.' The suppressed-exception is the "MalformedHTMLException" // // InnerTagGet.all; Returns a vector of TagNode's that resemble: // <META NAME="robots" ...> // // EQ_CI_TRM: Check the 'name' Attribute-Value using a Case-Insensitive, Equality // String-Comparison // Trim the 'name' Attribute-Value String of possible leading & trailing // White-Space before performing the comparison. return InnerTagGet .all (html, "META", "NAME", TextComparitor.EQ_CI_TRM, "robots") .stream () .map ((TagNode tn) -> tn.AV("CONTENT")) .filter ((String contents) -> (contents != null) && (contents.trim().length() > 0)) .map ((String contents) -> Arrays.asList(StrCSV.CSV(contents.toLowerCase()))) .collect (TreeSet<String>::new, TreeSet::addAll, TreeSet::addAll) .stream () .map ((String robotParam) -> Robots.getRobotNOMHE(robotParam)) .filter ((Robots robot) -> robot != null) .collect (Collectors.toCollection(Vector<Robots>::new));
-
getAllKeyWords
public static java.lang.String[] getAllKeyWords (java.util.Vector<? extends HTMLNode> html)
This method will extract any / all HTML<META NAME='keywords' ...>
Meta-Tags, and then extract the relevant page key-words. These key-words will be returned as a JavaString-Vector
.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- The list of words that were stored in the 'keywords' HTML Meta-Tags. If there
were no keywords in any
'KEYWORDS'
Meta-Tags, then an empty JavaString[]
-Array is returned.
Java Stream's Utility:
If the code below looks complicated, Java's Streams-Package does have a tendency to make simple things look difficult. However, once theStream
-Methods are understood, it's usually pretty useful for actually being very concise.- Get all HTML
<META name="keywords" content="...">
elements - Extracts the
CONTENT
-Attribute, and particularly the value stored there - Removes blanks, and
nulls
- Converts a
String[]
toList<String>
- Collects all the List
into a single java String-Array
- Get all HTML
- See Also:
insertKeyWords(Vector, String[])
,keyWordsMetaTag
,TagNode
,TagNode.AV(String)
,StrCSV.CSV(String)
- Code:
- Exact Method Body:
// Java Streams here both filter irrelevant meta tags, and also convert the type from // TagNode to String... using the 'map' function. Ultimately, those strings are // 'collected' into the returned vector. // ALSO SALIENT: the "Arrays.asList" produces an array of string, and the "::addAll" // puts each separate String into the returned Vector. // InnerTagGet.all: Returns a vector of TagNode's that resemble: // <META name="keywords" ...> // // EQ_CI_TRM: Check the 'name' Attribute-Value using a Case-Insensitive, Equality // String-Comparison // Trim the 'name' Attribute-Value String of possible leading & trailing // White-Space before performing the comparison. return InnerTagGet.all(html, "META", "NAME", TextComparitor.EQ_CI_TRM, "keywords") .stream () .map ((TagNode tn) -> tn.AV("content")) .filter ((String contents) -> (contents != null) && (contents.trim().length() > 0)) .map ((String contents) -> Arrays.asList(StrCSV.CSV(contents))) .collect (Vector::new, Vector::addAll, Vector::addAll) .stream () .toArray (String[]::new);
-
hasDescription
public static java.lang.String hasDescription (java.util.Vector<? extends HTMLNode> html) throws MalformedHTMLException
This method attempts to retrieve a'description'
-Property Meta-Tag out of an HTML_Page. If no such Meta-Tag is found, then null is returned.
If a partial Meta-Tag is found, but that tag is incomplete, then aMalformedHTMLException
will be thrown.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- The content-description that has been extracted from the HTML Meta-Tag
<META NAME="description" CONTENT="the-description">
.
If this tag is not found, then null is returned. If this tag is found, but does not posses aCONTENT
-Attribute, then aMalformedHTMLException
is thrown. - Throws:
MalformedHTMLException
- This is thrown if there are multiple definitions of the'ROBOTS'
Meta-Tag. There ought to only be a single definition, and if multiple are found, it would be better to identify why, and do the data-extraction manually. This is en-lieu of randomly picking one of them, and randomly returning one of the Meta-Tag'sCONTENT
-Attribute value.
This exception will also be thrown if proper-values for'index'
or'follow'
are not found in theCONTENT
-Attribute of the'ROBOTS'
Meta-Tag.
These are probably unlikely occurrences. This exception is a Checked-Exception and must have atry-catch
block or be declared thrown in your method-declaration.- See Also:
descriptionMetaTag
,insertDescription(Vector, String)
,InnerTagGet
- Code:
- Exact Method Body:
// InnerTagGet.all; Returns a vector of TagNode's that resemble: // <META NAME="description" ...> // // EQ_CI_TRM: Check the 'name' Attribute-Value using a Case-Insensitive, Equality // String-Comparison // Trim the 'name' Attribute-Value String of possible leading & trailing // White-Space before performing the comparison. Vector<TagNode> v = InnerTagGet.all (html, "META", "NAME", TextComparitor.EQ_CI_TRM, "description"); if (v.size() == 0) return null; if (v.size() > 1) throw new MalformedHTMLException( "You have asked for the value of the HTML 'description' <META ...> Tag, but " + "unfortunately there were multiple instances of this Tag on your page. " + "This is poorly formatted HTML, and not allowed here." ); String s = v.elementAt(0).AV("CONTENT"); if (s == null) throw new MalformedHTMLException( "An HTML Meta-Tag was found with a NAME-Attribute whose value was " + "'description,' but unfortunately this Meta-Tag did not posses a CONTENT-Attribute" ); return s;
-
hasAuthor
public static java.lang.String hasAuthor (java.util.Vector<? extends HTMLNode> html) throws MalformedHTMLException
This helps identify Web-Sites & Web-Pages "author-names" to Web-Indexing and Web-Search Organizations.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- This returns the author's name of a Web-Page, as delineated in the
'AUTHOR'
Meta-Tag, or null if the Web-Page parameter'html'
does not have an'AUTHOR'
Meta-Tag. - Throws:
MalformedHTMLException
- If multiple'AUTHOR'
Meta-Tags are found, this method is forced to throw an exception. It is necessary to avoid "picking a favorite author among a list".
HTML does not actually adhere to these exact requirements, so if there is such a scenario with a page having multiple-authors, this method throws an exception in order to avoid returning aString[]
-Array orVector<String>
which would be an alternative that would add unnecessary complexity.
If this method throws this exception, it is better to know about it, and just perform the search again, using a manual'AUTHOR'
retrieval. The code for extracting these properties is, indeed listed directly at the bottom.- See Also:
insertAuthor(Vector, String)
,authorMetaTag
,TagNode.AV(String)
- Code:
- Exact Method Body:
// InnerTagGet.all: Returns a vector of TagNode's that resemble: // <META name="author" ...> // // EQ_CI_TRM: Check the 'name' Attribute-Value using a Case-Insensitive, Equality // String-Comparison // Trim the 'name' Attribute-Value String of possible leading & trailing // White-Space before performing the comparison. Vector<TagNode> v = InnerTagGet.all (html, "META", "NAME", TextComparitor.EQ_CI_TRM, "author"); if (v.size() > 1) throw new MalformedHTMLException( "This method has identified multiple author Meta-Tags. To handle this " + "situation, the search should be performed manually using InnerTagGet, with " + "your code deciding what to do about the HTML Web-Page having multiple 'author' " + "Meta-Tags." ); // No HTML TagNode's were found that resembled <META NAME=author ...> if (v.size() == 0) return null; // Just return the first one that was found, always check for 'null' first to // avoid the embarrassing NullPointerException. String author = v.elementAt(0).AV("CONTENT"); if (author == null) return null; return author.trim();
-
getHTTPEquiv
public static java.lang.String getHTTPEquiv (java.util.Vector<HTMLNode> html, java.lang.String httpEquiv)
This method will find an HTML<META HTTP-EQUIV=... CONTENT=...>
element whoseHTTP-EQUIV
-Attribute's value is equal to theString
-Parameter'httpEquiv'
(ignoring case).
After such an HTMLMETA
-Tag has been identified, itsCONTENT
-AttributeString
-value will be subsequently queried, extracted and returned by this method.
Returning null, Gracefully:
If the page provided does not have an HTML Meta-Tag with aNAME
-Attribute whose value is'name'
or if such an element is identified, but that tag does not have aCONTENT
-Attribute, then this method will return null.
Case Insensitive Comparison:
Before the comparison is done with the'httpEquiv'
parameter, thatString
is trimmed withString.trim()
, and the comparison performed is done while ignoring case.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.httpEquiv
- The Attribute-name of theHTTP-EQUIV
-Attribute.- Returns:
- The
String
-value of theCONTENT
-Attribute for aMETA
-Tag whoseHTTP-EQUIV
-Attribute is equal to the specified name provided by parameter'httpEquiv'
.
If no such tag is found on the page, then this method shall return null. - Code:
- Exact Method Body:
// Find the first <META HTTP-EQUIV=... CONTENT=...> tag element where the name equals // the string-value provided by parameter 'httpEquiv'. TagNode tn = InnerTagGet.first (html, "META", "HTTP-EQUIV", TextComparitor.EQ_CI, httpEquiv.trim()); // If there are no <META HTTP-EQUIV='httpEquiv' CONTENT=...> elements found on the // page, then this method returns null. if (tn == null) return null; // Return the string-value of the attribute 'content'. Note that if this // attribute isn't available, this method shall return 'null', gracefully. return tn.AV("CONTENT");
-
getAllHTTPEquiv
public static java.util.Properties getAllHTTPEquiv (java.util.Vector<HTMLNode> html) throws MalformedHTMLException
This method will find all HTMLHTTP-EQUIV
-Directives, and return them in a JavaProperties
object.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- An instance of
java.util.Properties
containing allHTTP-EQUIV
-Directives. If HTML-Page paramter'html'
does not have any such Meta-Tags, then an emptyProperties
instance is returned, rather than null. - Throws:
MalformedHTMLException
- If the page provided has multiple definitions for the exact sameHTTP
-Header property, then this exception will throw.- Code:
- Exact Method Body:
Properties ret = new Properties(); String prev = null; // Find the first <META HTTP-EQUIV=... CONTENT=...> tag element where the name equals // the string-value provided by parameter 'httpEquiv'. for (TagNode httpEquivTN : InnerTagGet.all(html, "META", "HTTP-EQUIV")) if ((prev = (String) ret.put (httpEquivTN.AV("HTTP-EQUIV"), httpEquivTN.AV("CONTENT"))) != null) throw new MalformedHTMLException( "This HTML Page has multiple Meta-Tag Definitions for the HTTP-" + "EQUIVALENT Property [" + httpEquivTN.AV("HTTP-EQUIV") + "].\n" + " " + prev + "\n" + "and " + httpEquivTN.AV("CONTENT") + '\n' ); return ret;
-
hasUTF8MetaTag
public static boolean hasUTF8MetaTag (java.util.Vector<? extends HTMLNode> html)
This will detect whether aUTF-8
HTML Meta-Tag is included on this page. Below are examples of what such tags look like.
HTML Elements:
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta charset="UTF-8">
- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
TRUE
If an appropriate HTML Meta-Tag identifying this page as aUTF-8
Character-Set Web-Site. willFALSE
otherwise.- See Also:
hasUTF8MetaTag(Vector)
,UTF8MetaTag
,StrCmpr.containsAND_CI(String, String[])
,TagNode.AV(String)
- Code:
- Exact Method Body:
String s; // InnerTagGet.all: Returns a vector of TagNode's that resemble: // <META http-equiv="content-type" ...> // // EQ_CI_TRM: Check the 'http-equiv' Attribute-Value using a Case-Insensitive, // Equality String-Comparison // Trim the 'http-equiv' Attribute-Value String of possible leading & // trailing White-Space before performing the comparison. Vector<TagNode> v = InnerTagGet.all (html, "META", "HTTP-EQUIV", TextComparitor.EQ_CI_TRM, "content-type"); for (TagNode tn : v) if ((s = tn.AV("CONTENT")) != null) if (StrCmpr.containsAND_CI(s, "charset", "utf-8")) return true; // InnerTagGet.aall retrieves all TagNode's that resemble <META charset="utf-8" ...> // EQ_CI_TRM: Equality-Test, Case-Insensitive, Trim any White-Space before // performing comparison. v = InnerTagGet.all(html, "META", "CHARSET", TextComparitor.EQ_CI_TRM, "utf-8"); for (TagNode tn : v) if ((s = tn.AV("CHARSET")) != null) if (StrCmpr.containsAND_CI(s, "utf-8")) return true; return false;
-
insertMetaTagName
public static void insertMetaTagName (java.util.Vector<HTMLNode> html, MetaTagName m, java.lang.String contentAttributeValue)
This does a very simple insertion of an HTML Meta-Tag for a specific type, Meta-Tags that have both aNAME
-Attribute and aCONTENT
-Attribute set.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.m
- This is any of the enumerated-types of specific Meta-TagNAME
-Attribute &CONTENT
-Attribute pair / combinations.contentAttributeValue
- This is the value that will be used to set the value for theCONTENT
-Attribute.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- IfString
-Parameter'contentAttributeValue'
contains any single-quotation marks.- See Also:
metaTagName
,getAllMetaTagNames(Vector)
,DotPair
,TagNode
- Code:
- Exact Method Body:
// Builds and inserts a TagNode HTML Element that looks like: // <meta name='INSERT-NAME-STRING-HERE' content='INSERT-CONTENT-STRING-HERE'> // Single Quotes are used, so the attribute-value may not contain single quotes. checkForSingleQuote(contentAttributeValue); // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "<META NAME=... CONTENT=...> tag")); // Build a <META> tag, as in the comment above TagNode metaTN = new TagNode ("<META NAME='" + m.name + "' CONTENT='" + contentAttributeValue + "'>"); // Insert the meta-tag into the page. Put it at the top of the header, // just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
insertMetaTagNames
public static void insertMetaTagNames (java.util.Vector<HTMLNode> html, java.util.Hashtable<MetaTagName,java.lang.String> metaTags)
This does an insertion of a list of HTML Meta-Tags from a java Hashtable of Meta-Tag Name-Attribute / Content-Attribute pairs. All name-based Meta-Tags have both aNAME
-Attribute, and also aCONTENT
-Attribute.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.metaTags
- This is a hash-table of the enumerated-types of specific Meta-Tag Name property/content pairs.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- If any of the values from the key-value pair hash-table contain aString
that has a single-quotation mark, anywhere inside the it.- See Also:
metaTagName
,getAllMetaTagNames(Vector)
,insertMetaTagName(Vector, MetaTagName, String)
,TagNode
- Code:
- Exact Method Body:
// Builds and inserts a TagNode HTML Element that looks like: // "<meta name='INSERT-NAME-STRING-HERE' content='INSERT-CONTENT-STRING-HERE'"; // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "<META NAME=... CONTENT=...> tag")); // Java Stream's can be addictive... It is an easier way to build a list. Stream.Builder<HTMLNode> b = Stream.builder(); b.accept(NEWLINE); // Iterate the complete list of meta-tag names to insert for (MetaTagName m : metaTags.keySet()) { String contentAttributeValue = metaTags.get(m); checkForSingleQuote(contentAttributeValue); // Build the new node TagNode metaTN = new TagNode ("<META NAME='" + m.name + "' CONTENT='" + contentAttributeValue + "'>"); b.accept(metaTN); b.accept(NEWLINE); } // Insert the meta-tag names into the page. Put it at the top of the header, // just after <HEAD> Util.insertNodes(html, header.start + 1, b.build().toArray(HTMLNode[]::new));
-
insertRobots
public static void insertRobots(java.util.Vector<HTMLNode> html, boolean index, boolean follow)
One common HTML Meta-Tag is the one which informs Google & Yahoo (and all search-engine sites) which of your pages you would like to be indexed by their search engine, and which pages you would like to not be indexed. Worrying about what Google does and does not index may seem daunting, but this meta-tag can prevent certain behaviors.
The'ROBOTS'
Meta-Tag informs Search-Engines which pages on your site should be indexed. This Meta-Tag serves a similar purpose to a'robots.txt'
File. It is generally used to prevent a Search-Engine from indexing individual pages, while'robots.txt'
is used to prevent the search from indexing a whole site or section of a site.
A'ROBOTS'
Meta-Tag which instructs the Search-Engine Crawler not to index a page, or follow any links on it, would be written as below.
HTML Elements:
<meta name="robots" content="noindex, nofollow" /> <meta name="robots" content="index, follow" />
- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.index
- This is aboolean
-Parameter that when set toTRUE
will force this method to place anINDEX-String
into the finally-exported HTML element. IfFALSE
is passed, then aNOINDEX-String
will be put into the HTML-Tag.follow
- This is also aboolean
-Parameter. WhenTRUE
this will force the method to put aFOLLOW-String
into the finally-exported HTML-Tag. WhenFALSE
, then a'NOFOLLOW'
will be inserted.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.- See Also:
robotsMetaTag
,getAllRobots(Vector)
,getAllRobotsNOMHE(Vector)
,TagNode
- Code:
- Exact Method Body:
// Builds a robots meta tag. These are used by google and search engines // <meta NAME=robots content='INSERT-CONTENT-STRING-HERE' /> // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "Robots <META ... > Tag")); // Build a 'robots' TagNode TagNode robotsTN = new TagNode( "<META NAME=robots CONTENT='" + (index ? "index" : "noindex") + ", " + (follow ? "follow" : "nofollow") + "' >" ); // Insert the robots-tag into the page. // Put it at the top of the header, just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, robotsTN, NEWLINE);
-
insertRobots
public static void insertRobots(java.util.Vector<HTMLNode> html, Robots... rArr)
This will add an HTML Meta-Tag with a<META NAME=robots>
Validity Check Warning:
This method avoids all presumed validity check, primarily because making an attempt to identify what is absolutely correct or not-correct seems a little far-fetched.
Although the number of actual values theROBOTS
-Attribute may contain is very low, throwing aMalformedHTMLException
for some errors, while ignoring others was decided to best avoid during this method's development.
Aside:
If a programmer were to pass both theRobots.Follow
and theRobots.NoFollow
Enum-Constants, both of these tags would be inserted into an HTML'robots'
Meta-Tag without any kind of warning or exception throw.
This, clearly, would be a faulty HTML directive, though.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.rArr
- This is an array of the Enumerated-TypeRobots
. It may contain a list of any number of the items available to add into an HTML Meta-Tag'sROBOTS
-Attribute. If any of the array elements are null, they will be skipped and ignored.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.- See Also:
robotsMetaTag
,getAllRobots(Vector)
,insertRobots(Vector, boolean, boolean)
,StrCSV.toCSV(Object[], IntTFunction, boolean, Integer)
,DotPair
- Code:
- Exact Method Body:
// Builds a series-of-robots meta tag. These are used by google and search engines // <meta NAME=robots content='INSERT-CONTENT-STRING-HERE' /> // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "Robots <META ... > Tag")); String robotsStr = StrCSV.toCSV(rArr, (int i, Robots r) -> r.name, false, null); // Build the <META> TagNode TagNode robotsTN = new TagNode("<META NAME=robots CONTENT='" + robotsStr + "'>"); // Insert the robots-tag into the page. Put it at the top of the header, just // after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, robotsTN, NEWLINE);
-
insertDescription
public static void insertDescription(java.util.Vector<HTMLNode> html, java.lang.String description)
Another common HTMLMETA
-Tag is the one that provides a brief description of the page in question. This method facilitates adding a Meta-Tag that contains two attributes:-
NAME
-Attribute whose value must be'description'
-
CONTENT
-Attribute whose value should be a brief textual description of the content of the page
- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.description
- This is a textual-description of the Web-Page to which this HTML<META NAME=description CONTENT='...'
Tag is being added. If Google or any of the other Internet Search Sites, return your Web-Page as a part of a search-results, this description is usually used.
Furthermore, the key-words that are listed here are some-how (in a way that is not-knownst to this programmer) used in indexing your particular page in the search-algorithms.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- IfString
-Parameter'description'
contains any single-quotation marks.- See Also:
descriptionMetaTag
,hasDescription(Vector)
,Features.checkForSingleQuote(String)
,TagNode
- Code:
- Exact Method Body:
// Meta-Tag for Descriptions. This will be inserted into the HTML page. // <meta NAME=description content='INSERT-DESCRIPTION-OR-KEYWORDS-HERE'> checkForSingleQuote(description); // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "Description <META ... > Tag")); // Build the Meta Tag for a description to google and search engines TagNode metaTN = new TagNode ("<META NAME=description CONTENT='" + description + "'>"); // Insert the description-tag into the page. Put it at the top of the header, // just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
-
insertKeyWords
public static void insertKeyWords(java.util.Vector<HTMLNode> html, java.lang.String... keyWords)
This will attempt to insert key-words into an HTML Meta-Tag. This is usually used to summarize-explain 'main-points' that a Web-Page author wants to make to any search-engineer or any-listener on the internet about the Web-Page that includes such a Meta-Tag.
Validity Checking:
This method does a few minor validity checks regarding the content inside of a description keyword. All it does is look for things like White-Space and a few punctuation rules. If either of these problems occur inside any of the key-words provided to the'keyWords'
Var-Args Parameter, then anIllegalArgumentException
is thrown.
Disallowed Punctuation:
This list of disallowed punctuation marks for the key-words are as processed as follows:
if (StrCmpr.containsOR (keyWord, ";", ",", "'", "\"", "!", "#", "<", ">", "(", ")", "*", "/", "\\") ) throw new IllegalArgumentException(...);
- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.keyWords
- This is a list of germane key-words that help identify, indicate or describe the content of the Web-Page in which they are placed.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.java.lang.IllegalArgumentException
- If any of the key-words provided to the Java Var-Args'keyWords'
parameter contain invalid punctuation characters, or white-space.- See Also:
keyWordsMetaTag
,getAllKeyWords(Vector)
,StringParse.hasWhiteSpace(String)
,StrCmpr.containsOR(String, String[])
,StrCSV.toCSV(String[], boolean, boolean, Integer)
- Code:
- Exact Method Body:
// The meta-tag for key-words. Search Engines look for these key-words when indexing // <meta NAME=keywords content='INSERT-COMMA-SEPARATED-KEYWORDS-HERE'> // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "KeyWords Meta-Tag")); for (String keyWord : keyWords) if (StringParse.hasWhiteSpace(keyWord)) throw new IllegalArgumentException( "You have tried to insert keywords into an HTML Meta-Tag KeyWord-{roperty, " + "but unfortunately one of the words provided [" + keyWord + "] contains " + "white-space. This is not allowed here." ); for (String keyWord : keyWords) if (StrCmpr.containsOR (keyWord, ";", ",", "'", "\"", "!", "<", ">", "(", ")", "*", "/", "\\")) throw new IllegalArgumentException( "You have tried to insert keywords into an HTML Meta-Tag KeyWords-" + "Property, but unfortunately one of the words provide [" + keyWord + "] " + "contains error-prone punctuation, and cannot be used here." ); // All this does is build a list - Comma Separated values. String listAsString = StrCSV.toCSV(keyWords, true, false, null); // Build the TagNode, it will contain all key-words listed in the input var-args // String array TagNode metaTN = new TagNode("<META NAME=keywords CONTENT='" + listAsString + "'>"); // Insert the tag into the page. Put it at the top of the header, just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
insertAuthor
public static void insertAuthor(java.util.Vector<HTMLNode> html, java.lang.String author)
This method will insert an "author" HTML Meta-Tag into the<HEAD> ... </HEAD>
section of this page.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.author
- This is the author of this Web-Page.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- If the author's name prevents the HTML-Engine from building any version of anAUTHOR
Meta-Tag. This will happen, certainly, if the author's name-String
contains both a single and a double quote.
Choose either the single-quote, or the double. Do not use both, or this exception will throw.
MOST IMPORTANT Most author's names don't have any quotes at all! Checking for these things prevents unexplainable exceptions later on.- See Also:
authorMetaTag
,hasAuthor(Vector)
,SD
,DotPair
- Code:
- Exact Method Body:
// The 'Author' Meta tag shall be inserted into the html page. // <meta NAME=author content='INSERT-AUTHOR-NAME-HERE'> // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "author meta-tag")); if ((author.indexOf("'") != -1) && (author.indexOf("\"") != -1)) throw new QuotesException( "The author string provided here contains both a single-quote and a double-" + "quote, but this cannot be inserted into any HTML-Tag. Please remove " + "one or the other." ); // Use the more complicated TagNode constructor to build the "author" tag. SD quote = (author.indexOf("'") == -1) ? SD.SingleQuotes : SD.DoubleQuotes; Properties p = new Properties(); p.put("NAME", "author"); p.put("CONTENT", author); // This constructor accepts a properties instance. TagNode authorTN = new TagNode("META", p, quote, true); // Insert the tag into the page. Put it at the top of the header, just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, authorTN, NEWLINE);
-
insertHTTPEquiv
public static void insertHTTPEquiv(java.util.Vector<HTMLNode> html, java.lang.String httpEquiv, java.lang.String contentAttributeValue)
This does a very simple insertion of an HTML Meta-Tag for a specific type, Meta-Tags that have aHTTP-EQUIV
-Attribute paired with aCONTENT
-Attribute.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.httpEquiv
- This is the property that is passed using theHTTP-EQUIV
-Attribute.contentAttributeValue
- This is the value that will be used to set theCONTENT
-Attribute.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- IfString
-Parameter'contentAttributeValue'
contains any single-quotation marks.- See Also:
metaTagHTTPEquiv
,getHTTPEquiv(Vector, String)
,DotPair
,TagNode
- Code:
- Exact Method Body:
// Builds and inserts a TagNode HTML Element that looks like: // <meta http-equiv='INSERT-HTTP-EQUIV-STRING-HERE' // content='INSERT-CONTENT-STRING-HERE' > // Single Quotes are used, so the attribute-value may not contain single quotes. checkForSingleQuote(contentAttributeValue); // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "<META HTTP-EQUIV=... CONTENT=...> Tag")); // Build a <META> tag, as in the comment above TagNode metaTN = new TagNode ("<META HTTP-EQUIV='" + httpEquiv + "' CONTENT='" + contentAttributeValue + "'>"); // Insert the meta-tag into the page. Put it at the top of the header, // just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
insertUTF8MetaTag
public static void insertUTF8MetaTag(java.util.Vector<HTMLNode> html)
The method will insert aUTF-8
Meta-Tag that identifies the HTML-Page to any Web-Browser that attempts to render its content as containing Foreign-Language Characters, Emoji's & other non-ASCII
Glyphs.UTF-8
text utilizes/makes-use-of characters in a higher'byte-range'
than the traditional single-byte (256 different-characters) ASCII Character-Set.UTF-8
allows for Chinese, Japanese and just about every variant of language in the rest of the world.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.- See Also:
hasUTF8MetaTag(Vector)
,UTF8MetaTag
,TagNode
,DotPair
- Code:
- Exact Method Body:
// Meta-Tag to assert that the UTF-8 Charset is being used: // <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "UTF-8 <META> Tag")); // Insert the UTF-8 tag into the page. Put it at the top of the header, just // after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, new TagNode(UTF8MetaTag), NEWLINE);
-
insertItemProp
public static void insertItemProp(java.util.Vector<HTMLNode> html, java.lang.String itemProp, java.lang.String contentAttributeValue)
This does a very simple insertion of an HTML Meta-Tag for a specific type, Meta-Tags that have anITEMPROP
-Attribute paired with aCONTENT
-Attribute set.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.itemProp
- This is a property that is passed via theITEMPROP
-AttributecontentAttributeValue
- This is the value that will be used to set theCONTENT
-Attribute- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- IfString
-Parameter'contentAttributeValue'
contains any single-quotation marks.- See Also:
metaTagItemProp
,getItemProp(Vector, String)
,DotPair
,TagNode
- Code:
- Exact Method Body:
// Builds and inserts a TagNode HTML Element that looks like: // <meta itemprop='INSERT-ITEMPROP-STRING-HERE' content='INSERT-CONTENT-STRING-HERE' > // Single Quotes are used, so the attribute-value may not contain single quotes. checkForSingleQuote(contentAttributeValue); // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException (NO_HEADER_MESSAGE.replace("INSERT-STR", "<META ITEMPROP=... CONTENT=...> tag")); // Build a <META> tag, as in the comment above TagNode metaTN = new TagNode ("<META ITEMPROP='" + itemProp + "' CONTENT='" + contentAttributeValue + "'>"); // Insert the meta-tag into the page. Put it at the top of the header, // just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
getItemProp
public static java.lang.String getItemProp (java.util.Vector<HTMLNode> html, java.lang.String itemProp)
This method will find an HTML<META ITEMPROP=... CONTENT=...>
element whoseITEMPROP
-Attribute value is equal to theString
-parameter'itemProp'
(ignoring case).
After such an HTMLMETA
-Tag has been identified, itsCONTENT
-AttributeString
-value will be subsequently queried, extracted and returned by this method.
Returning null, Gracefully:
If the page provided does not have an HTML Meta-Tag with aNAME
-Attribute whose value is'name'
or if such an element is identified, but that tag does not have aCONTENT
-Attribute, then this method will return null.
Case Insensitive Comparison:
Before the comparison is done with the'itemProp'
parameter, thatString
is trimmed withString.trim()
, and the comparison performed is done while ignoring case.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.itemProp
- The Attribute-name of theITEMPROP
-Attribute.- Returns:
- The
String
-value of theCONTENT
-Attribute for aMETA
-Tag whoseITEMPROP
-Attribute is equal to the specified name provided by parameter'itemProp'
.
If such information is not found on the page, then this method returns null. - Code:
- Exact Method Body:
// Find the first <META ITEMPROP=... CONTENT=...> tag element where the name equals // the string-value provided by parameter 'itemProp'. TagNode tn = InnerTagGet.first (html, "META", "ITEMPROP", TextComparitor.EQ_CI, itemProp.trim()); // If there are no <META ITEMPROP='itemProp' CONTENT=...> elements found on the page, // then this method returns null. if (tn == null) return null; // Return the string-value of the attribute 'content'. Note that if this // attribute isn't available, this method shall return 'null', gracefully. return tn.AV("content");
-
insertOGMetaTag
public static void insertOGMetaTag(java.util.Vector<HTMLNode> html, java.lang.String ogProperty, java.lang.String ogValueAsStr)
This will insert a single Open-Graph Meta-Tag into an HTML-Page.
Prepending'og:'
The name of the property MUST NOT begin with the characters"og:"
, because they will be prepended when the HTML<META PROPERTY='...' CONTENT='...' />
Tag is instantiated.
Please review exact method body below.- Parameters:
html
- Any Vectorized-HTML Web-Page, but it is important that this page contain an HTML <HEAD> ... </HEAD> section or area. If the passed Vectorized-HTML does not have a header, then this method will throw aNodeNotFoundException
because whenever a <META>-Tag is inserted, it must be inserted into a page'sHEAD
-Section.ogProperty
- This is the name of the Open-Graph protocol property that is being inserted. Generally these are simple text-String's
with alphanumeric-limited names, or they are series of alphanumeric text-String's
, separated by a period'.'
character.ogValueAsStr
- If you look at the definition of theopenGraphMetaTag
above in this class, you may view all of the acceptable types that Open-Graph Properties may use.
Whichever property or field that is being inserted, mostly, the field must be converted to aString
when being passed to this method.- Throws:
NodeNotFoundException
- Throws if there is no HTMLHEAD
-Section. Specifically, if parameter'html'
doesn't have a <HEAD> ... </HEAD> element where the insertion would have to be performed, then this exception will throw.QuotesException
- If either of theString
-Parameter's'ogProperty'
or'ogValueAsStr'
contain any single-quotation marks.- See Also:
openGraphMetaTag
,getAllOGMetaTags(Vector)
,Features.checkForSingleQuote(String)
,TagNode
- Code:
- Exact Method Body:
// Open graph tag looks like this: // <meta property='og:INSERT-OG-PROPERTY-HERE' content='INSERT-OG-VALUE-HERE' /> checkForSingleQuote(ogProperty); checkForSingleQuote(ogValueAsStr); // The HTML Page must have a <HEAD> ... </HEAD> section, or an exception shall throw. DotPair header = TagNodeFindInclusive.first(html, "HEAD"); if (header == null) throw new NodeNotFoundException( NO_HEADER_MESSAGE.replace ("INSERT-STR", "Open-Graph <META NAME='og:...' ...> Tag") ); // Build the Open-Graph Meta Tag TagNode metaTN = new TagNode ("<META PROPERTY='og:" + ogProperty+ "' CONTENT='" + ogValueAsStr +"'>"); // Insert the tag into the page. Put it at the top of the header, just after <HEAD> Util.insertNodes(html, header.start + 1, NEWLINE, metaTN, NEWLINE);
-
getAllOGMetaTags
public static java.util.Properties getAllOGMetaTags (java.util.Vector<? extends HTMLNode> html)
This will search any Vectorized HTML-Pge for<META PROPERTY='og:...' CONTENT='...'>
Tags, and retrieve them for placement into ajava.util.Properties
table.- Parameters:
html
- This may be any Vectorized-HTML Web-Page (or sub-page).
The Variable-Type Wild-Card Expression'? extends HTMLNode'
means that aVector<TagNode>, Vector<TextNode>
orVector<CommentNode>
will all be accepted by this paramter without causing an exception throw.
These 'sub-type' Vectors are often returned as search results from the classes in the'NodeSearch'
vpackage.- Returns:
- This will return a Java
'Properties'
Object, with all Open-Graph properties saved inside. - See Also:
openGraphMetaTag
,insertOGMetaTag(Vector, String, String)
,TagNode.AV(String)
,InnerTagGet
- Code:
- Exact Method Body:
// InnerTagGet.all: Returns a vector of TagNode's that resemble: // <META property="og:..." ...> // // SW_CI_TRM: Check the 'property' Attribute-Value using a Case-Insensitive, // 'Starts-With' String-Comparison // Trim the 'property' Attribute-Value String of possible leading & // trailing White-Space before performing the comparison. Vector<TagNode> v = InnerTagGet.all (html, "META", "PROPERTY", TextComparitor.SW_CI_TRM, "og:"); Properties ret = new Properties(); for (TagNode tn : v) ret.put(tn.AV("PROPERTY").substring(3), tn.AV("CONTENT")); return ret;
-
-