Java Question Casting library type to my type

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hello all ,

I am not sure if it is clear but my problem occurs when trying to wrap a library that has types (class ) like this

B4X:
java.lang.ClassCastException: com.other.library.someclass cannot be cast to smm.mylib.someclass

How can I use same class or write a type wrapper ?

So I can use

B4X:
Dim some as sometype
some = mylibrary.someclassthatreturnssometype

I hope it is clear :D

and thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User

somed3v3loper

Well-Known Member
Licensed User
Longtime User
No
Upload a sample. Including javasources
For example
B4X:
public Document parseInput(String html, String baseUri) {
        errors = isTrackErrors() ? ParseErrorList.tracking(maxErrors) : ParseErrorList.noTracking();
        return treeBuilder.parse(html, baseUri, errors);
    }
How to return Document with its properties to b4a ?
Or how to expose Document properties to B4A?
 

DonManfred

Expert
Licensed User
Longtime User

somed3v3loper

Well-Known Member
Licensed User
Longtime User
I guess you need to write a wrapper-class for the Document object too. with this you then can have access to properties/methods or the Object.
Should my wrapper extends the original Document ?
And if possible can you give a very simple sample I just don't know where and how to start wrapping such type of classes ?
Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
must be something like this i guess

B4X:
package de.donmanfred;

import java.nio.charset.Charset;

import org.jsoup.helper.StringUtil;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Document.OutputSettings;
import org.jsoup.nodes.Document.QuirksMode;
import org.jsoup.parser.Tag;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.CompoundButton.OnCheckedChangeListener;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DesignerProperties;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Pixel;
import anywheresoftware.b4a.BA.Property;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.keywords.Common.DesignerCustomView;
import anywheresoftware.b4a.objects.CustomViewWrapper;
import anywheresoftware.b4a.objects.LabelWrapper;
import anywheresoftware.b4a.objects.PanelWrapper;
import anywheresoftware.b4a.objects.ViewWrapper;
import anywheresoftware.b4a.objects.collections.Map;

@Version(1.00f)
@ShortName("Document")
@Author(value = "DonManfred (wrapper)")
//@Permissions(values={"android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE"})
//@Events(values={"onSigned(sign As Object)"})
//@DependsOn(values={"android-viewbadger"})
//@DesignerProperties(values = {
//        @Property(key="Checked", displayName="Checked", defaultValue="False", fieldType="Boolean")
//    })
public class DocumentWrapper extends AbsObjectWrapper<Document>{
    private BA ba;
    private String eventName;

    public void Initialize(final BA ba, String EventName, String baseUri) {
        this.eventName = EventName.toLowerCase(BA.cul);
        this.ba = ba;

        final Document _obj = new Document(baseUri);
        final String eventName = EventName.toLowerCase(BA.cul);
        setObject(_obj);
    }
  /**
  Create a valid, empty shell of a document, suitable for adding more elements to.
  @param baseUri baseUri of document
  @return document with html, head, and body elements.
  */
public Document createShell(String baseUri) {
     return this.getObject().createShell(baseUri);
}

/**
  * Get the URL this Document was parsed from. If the starting URL is a redirect,
  * this will return the final URL from which the document was served from.
  * @return location
  */
public String location() {
  return this.getObject().location();
}
/**
  Accessor to the document's {@code head} element.
  @return {@code head}
  */
public Element head() {
     return this.getObject().head();
}

/**
  Accessor to the document's {@code body} element.
  @return {@code body}
  */
public Element body() {
     return this.getObject().body();
}

/**
  Get the string contents of the document's {@code title} element.
  @return Trimmed title, or empty string if none set.
  */
public String title() {
     return this.getObject().title();
}

/**
  Set the document's {@code title} element. Updates the existing element, or adds {@code title} to {@code head} if
  not present
  @param title string to set as title
  */
public void title(String title) {
     this.getObject().title(title);
}

/**
  Create a new Element, with this document's base uri. Does not make the new element a child of this document.
  @param tagName element tag name (e.g. {@code a})
  @return new element
  */
public Element createElement(String tagName) {
     return this.getObject().createElement(tagName);
}

/**
  Normalise the document. This happens after the parse phase so generally does not need to be called.
  Moves any text content that is not in the body element into the body.
  @return this document after normalisation
  */
public Document normalise() {
     return this.getObject().normalise();
}
/**
Set the text of the {@code body} of this document. Any existing nodes within the body will be cleared.
@param text unencoded text
@return this document
*/
public Element text(String text) {
    return this.getObject().text(text);
}

public String nodeName() {
    return this.getObject().nodeName();
}

/**
  * Sets the charset used in this document. This method is equivalent
  * to {@link OutputSettings#charset(java.nio.charset.Charset)
  * OutputSettings.charset(Charset)} but in addition it updates the
  * charset / encoding element within the document.
  *
  * <p>This enables
  * {@link #updateMetaCharsetElement(boolean) meta charset update}.</p>
  *
  * <p>If there's no element with charset / encoding information yet it will
  * be created. Obsolete charset / encoding definitions are removed!</p>
  *
  * <p><b>Elements used:</b></p>
  *
  * <ul>
  * <li><b>Html:</b> <i>&lt;meta charset="CHARSET"&gt;</i></li>
  * <li><b>Xml:</b> <i>&lt;?xml version="1.0" encoding="CHARSET"&gt;</i></li>
  * </ul>
  *
  * @param charset Charset
  *
  * @see #updateMetaCharsetElement(boolean)
  * @see OutputSettings#charset(java.nio.charset.Charset)
  */
public void charset(Charset charset) {
     this.getObject().charset(charset);
}

/**
  * Returns the charset used in this document. This method is equivalent
  * to {@link OutputSettings#charset()}.
  *
  * @return Current Charset
  *
  * @see OutputSettings#charset()
  */
public Charset charset() {
     return this.getObject().charset();
}

/**
* Sets whether the element with charset information in this document is
* updated on changes through {@link #charset(java.nio.charset.Charset)
* Document.charset(Charset)} or not.
*
* <p>If set to <tt>false</tt> <i>(default)</i> there are no elements
* modified.</p>
*
* @param update If <tt>true</tt> the element updated on charset
* changes, <tt>false</tt> if not
*
* @see #charset(java.nio.charset.Charset)
*/
public void updateMetaCharsetElement(boolean update) {
    this.getObject().updateMetaCharsetElement(update);
}

/**
* Returns whether the element with charset information in this document is
* updated on changes through {@link #charset(java.nio.charset.Charset)
* Document.charset(Charset)} or not.
*
* @return Returns <tt>true</tt> if the element is updated on charset
* changes, <tt>false</tt> if not
*/
public boolean updateMetaCharsetElement() {
     return this.getObject().updateMetaCharsetElement();
}

public Document clone() {
     return this.getObject().clone();
}
/**
  * Get the document's current output settings.
  * @return the document's current output settings.
  */
public OutputSettings outputSettings() {
    return this.getObject().outputSettings();
}

/**
* Set the document's output settings.
* @param outputSettings new output settings.
* @return this document, for chaining.
*/
public Document outputSettings(OutputSettings outputSettings) {
     return this.getObject().outputSettings(outputSettings);
}

public QuirksMode quirksMode() {
     return this.getObject().quirksMode();
}

public Document quirksMode(QuirksMode quirksMode) {
     return this.getObject().quirksMode(quirksMode);
}
       
}
 
Top