Search in sources :

Example 11 with Node

use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.

the class ElementPropertiesPanel method tableModel.

private TableModel tableModel(Node node) {
    if (node.getNodeType() != NodeType.ELEMENT_NODE) {
        Toolkit.getDefaultToolkit().beep();
        return _defaultTableModel;
    }
    HTMLElementImpl elm = (HTMLElementImpl) node;
    Map<String, String> cssProperties = new HashMap<>();
    final String classNames = elm.getClassName();
    final String elementName = elm.getTagName();
    final String[] classNameArray = Strings.isNotBlank(classNames) ? Strings.split(classNames) : null;
    final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = elm.findStyleDeclarations(elementName, classNameArray, false);
    for (CSSStyleSheetImpl.SelectorEntry entry : matchingRules) {
        final CSSStyleDeclarationImpl styleDeclaration = entry.getRule().getStyle();
        styleDeclaration.getProperties().forEach(prop -> {
            final String propertyName = prop.getName();
            final String propertyValue = styleDeclaration.getPropertyValue(propertyName);
            cssProperties.put(propertyName.toLowerCase(), propertyValue);
        });
    }
    List<CSSStyleDeclarationImpl> styleDeclaration = elm.getStyle().getStyleDeclarations();
    if (styleDeclaration != null) {
        styleDeclaration.forEach(decl -> decl.getProperties().forEach(prop -> {
            final String propertyName = prop.getName();
            final String propertyValue = decl.getPropertyValue(propertyName);
            cssProperties.put(propertyName.toLowerCase(), propertyValue);
        }));
    }
    return new PropertiesTableModel(cssProperties);
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl) HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) NodeType(org.loboevolution.html.node.NodeType) TableColumnModel(javax.swing.table.TableColumnModel) DefaultTableModel(javax.swing.table.DefaultTableModel) HashMap(java.util.HashMap) java.awt(java.awt) List(java.util.List) Strings(org.loboevolution.common.Strings) Node(org.loboevolution.html.node.Node) Map(java.util.Map) CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) javax.swing(javax.swing) TableModel(javax.swing.table.TableModel) CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) HashMap(java.util.HashMap) CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)

Example 12 with Node

use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.

the class HTMLOptionsCollectionImpl method addElements.

private void addElements(HTMLOptionElement element, HTMLElement before) {
    List<Node> nodeList = getList();
    if (nodeList.size() == 0) {
        nodeList.add(0, element);
    } else {
        boolean found = false;
        HTMLOptionElement bef = (HTMLOptionElement) before;
        for (int i = 0; i < nodeList.size(); i++) {
            HTMLOptionElement elem = (HTMLOptionElement) nodeList.get(i);
            if (elem.getText().equals(bef.getText())) {
                nodeList.add(i, element);
                found = true;
                break;
            }
        }
        if (!found)
            throw new DOMException(DOMException.NOT_FOUND_ERR, "Record not found");
    }
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) HTMLOptionElement(org.loboevolution.html.dom.HTMLOptionElement) Node(org.loboevolution.html.node.Node)

Example 13 with Node

use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.

the class SVGClipPathElementImpl method getClippingShape.

/**
 * <p>getClippingShape.</p>
 *
 * @param clippedElement a {@link org.loboevolution.html.dom.svg.SVGElement} object.
 * @return a {@link java.awt.Shape} object.
 */
protected Shape getClippingShape(SVGElement clippedElement) {
    Area clipArea = null;
    AffineTransform clipTransform = new AffineTransform();
    if (hasChildNodes()) {
        NodeListImpl children = (NodeListImpl) getChildNodes();
        for (Node child : children) {
            if (child instanceof SVGUseElementImpl) {
                String href = ((SVGUseElementImpl) child).getHref().getAnimVal();
                if (href.length() > 0) {
                    int index = href.indexOf('#');
                    if (index != -1) {
                        String id = href.substring(index + 1).trim();
                        Element ref = (Element) child(id);
                        if (ref != null) {
                            Shape childShape = ((Drawable) ref).createShape(clipTransform);
                            if (childShape != null) {
                                AffineTransform childAffineTransform = clipTransform;
                                if (ref instanceof SVGTransformable) {
                                    SVGTransformListImpl childTransform = (SVGTransformListImpl) ((SVGTransformable) ref).getTransform().getAnimVal();
                                    if (childTransform != null) {
                                        childAffineTransform.concatenate(childTransform.getAffineTransform());
                                    }
                                }
                                GeneralPath path = new GeneralPath(childShape);
                                path.transform(childAffineTransform);
                                String clipRule = ((SVGStylableImpl) child).getClipRule();
                                SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
                                if (clipRule.equals("evenodd")) {
                                    path.setWindingRule(Path2D.WIND_EVEN_ODD);
                                } else {
                                    path.setWindingRule(Path2D.WIND_NON_ZERO);
                                }
                                Area childClipArea = new Area(path);
                                if (clipPath != null) {
                                    Shape clipShape = clipPath.getClippingShape(clippedElement);
                                    if (clipShape != null) {
                                        childClipArea.intersect(new Area(clipShape));
                                    }
                                }
                                if (clipArea == null) {
                                    clipArea = childClipArea;
                                } else {
                                    clipArea.add(childClipArea);
                                }
                            }
                        }
                    }
                }
            } else if (child instanceof Drawable) {
                Shape childShape = ((Drawable) child).createShape(clipTransform);
                if (childShape != null) {
                    if (child instanceof SVGTransformable) {
                        SVGAnimatedTransformListImpl childTransform = (SVGAnimatedTransformListImpl) ((SVGTransformable) child).getTransform();
                        if (childTransform != null) {
                            clipTransform.concatenate(((SVGTransformListImpl) childTransform.getAnimVal()).getAffineTransform());
                        }
                    }
                    GeneralPath path = new GeneralPath(childShape);
                    path.transform(clipTransform);
                    String clipRule = ((SVGStylableImpl) child).getClipRule();
                    SVGClipPathElementImpl clipPath = ((SVGStylableImpl) child).getClippingPath();
                    if (clipRule.equals("evenodd")) {
                        path.setWindingRule(Path2D.WIND_EVEN_ODD);
                    } else {
                        path.setWindingRule(Path2D.WIND_NON_ZERO);
                    }
                    Area childClipArea = new Area(path);
                    // see if child has a clipPath property
                    if (clipPath != null) {
                        Shape clipShape = clipPath.getClippingShape(clippedElement);
                        if (clipShape != null) {
                            childClipArea.intersect(new Area(clipShape));
                        }
                    }
                    if (clipArea == null) {
                        clipArea = childClipArea;
                    } else {
                        clipArea.add(childClipArea);
                    }
                }
            }
        }
    }
    SVGClipPathElementImpl clipPath = getClippingPath();
    getClipRule();
    if (clipPath != null) {
        Shape clipShape = clipPath.getClippingShape(clippedElement);
        if (clipShape != null) {
            if (clipArea == null) {
                clipArea = new Area(clipShape);
            } else {
                clipArea.intersect(new Area(clipShape));
            }
        }
    }
    if (clipArea != null) {
        Shape clipShape = clipArea;
        if (getClipPathUnits().getAnimVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
            SVGRectImpl bbox = null;
            if (clippedElement instanceof SVGTransformable) {
                bbox = (SVGRectImpl) ((SVGTransformable) clippedElement).getBBox();
            } else if (clippedElement instanceof SVGSVGElementImpl) {
                bbox = (SVGRectImpl) ((SVGSVGElementImpl) clippedElement).getBBox();
            }
            if (bbox != null) {
                AffineTransform clipTrans = AffineTransform.getTranslateInstance(bbox.getX(), bbox.getY());
                clipTrans.scale(bbox.getWidth(), bbox.getHeight());
                clipShape = clipTrans.createTransformedShape(clipShape);
                return clipShape;
            }
        }
    }
    return clipArea;
}
Also used : Shape(java.awt.Shape) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) Node(org.loboevolution.html.node.Node) Element(org.loboevolution.html.node.Element)

Example 14 with Node

use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.

the class XPathNSResolverImpl method lookupNamespaceURI.

/**
 * {@inheritDoc}
 */
@Override
public String lookupNamespaceURI(String prefix) {
    String namespace = null;
    if (prefix.equals("xml")) {
        namespace = Constants.S_XMLNAMESPACEURI;
    } else {
        int type;
        while ((null != parent) && (null == namespace) && (((type = parent.getNodeType()) == NodeType.ELEMENT_NODE) || ((type = parent.getNodeType()) == NodeType.DOCUMENT_NODE) || (type == NodeType.ENTITY_REFERENCE_NODE))) {
            if (type == NodeType.DOCUMENT_NODE) {
                Document document = (Document) parent;
                Element docelm = document.getDocumentElement();
                if (docelm != null && docelm.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
                    return docelm.getNamespaceURI();
                }
            }
            if (type == NodeType.ELEMENT_NODE) {
                if (parent.getNodeName().indexOf(prefix.toUpperCase() + ":") == 0) {
                    return parent.getNamespaceURI();
                }
                NamedNodeMap nnm = ((Element) parent).getAttributes();
                for (int i = 0; i < nnm.getLength(); i++) {
                    Node attr = nnm.item(i);
                    String aname = attr.getNodeName();
                    boolean isPrefix = aname.startsWith("xmlns:");
                    if (isPrefix || aname.equals("xmlns")) {
                        int index = aname.indexOf(':');
                        String p = isPrefix ? aname.substring(index + 1) : "";
                        if (p.equals(prefix)) {
                            namespace = attr.getNodeValue();
                            break;
                        }
                    }
                }
            }
            parent = parent.getParentNode();
        }
    }
    return namespace;
}
Also used : NamedNodeMap(org.loboevolution.html.node.NamedNodeMap) Element(org.loboevolution.html.node.Element) Node(org.loboevolution.html.node.Node) Document(org.loboevolution.html.node.Document)

Example 15 with Node

use of org.loboevolution.html.node.Node in project LoboEvolution by LoboEvolution.

the class XPathResultImpl method getSingleNodeValue.

/**
 * {@inheritDoc}
 */
@Override
public Node getSingleNodeValue() throws XPathException {
    if (m_resultType != ANY_UNORDERED_NODE_TYPE && m_resultType != FIRST_ORDERED_NODE_TYPE) {
        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] { m_xpath.getPatternString(), getTypeString(m_resultType) });
        throw new XPathException(XPathException.TYPE_ERR, fmsg);
    // "The XPathResult of XPath expression {0} has an XPathResultType
    // of {1} which cannot be converted to a single node.
    // This method applies only to types ANY_UNORDERED_NODE_TYPE and
    // FIRST_ORDERED_NODE_TYPE."
    }
    NodeIterator result = null;
    if (null == result) {
        return null;
    }
    Node node = result.nextNode();
    if (isNamespaceNode(node)) {
        return new XPathNamespaceImpl(node);
    } else {
        return node;
    }
}
Also used : NodeIterator(org.loboevolution.html.node.NodeIterator) XPathException(org.loboevolution.html.xpath.XPathException) Node(org.loboevolution.html.node.Node)

Aggregations

Node (org.loboevolution.html.node.Node)30 NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)5 Document (org.loboevolution.html.node.Document)5 Element (org.loboevolution.html.node.Element)5 DOMException (com.gargoylesoftware.css.dom.DOMException)3 ArrayList (java.util.ArrayList)3 CSSStyleDeclarationImpl (com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)2 CSSStyleSheetImpl (com.gargoylesoftware.css.dom.CSSStyleSheetImpl)2 HTMLCollection (org.loboevolution.html.dom.HTMLCollection)2 NodeList (org.loboevolution.html.node.NodeList)2 CSSErrorHandler (com.gargoylesoftware.css.parser.CSSErrorHandler)1 CSSException (com.gargoylesoftware.css.parser.CSSException)1 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)1 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)1 Condition (com.gargoylesoftware.css.parser.condition.Condition)1 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)1 java.awt (java.awt)1 Shape (java.awt.Shape)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1