private void importOpmlElement()

in app/src/main/java/org/apache/roller/weblogger/business/jpa/JPABookmarkManagerImpl.java [168:222]


    private void importOpmlElement(
            Element elem, WeblogBookmarkFolder folder)
            throws WebloggerException {
        String text = elem.getAttributeValue("text");
        String title = elem.getAttributeValue("title");
        String desc = elem.getAttributeValue("description");
        String url = elem.getAttributeValue("url");
        String xmlUrl = elem.getAttributeValue("xmlUrl");
        String htmlUrl = elem.getAttributeValue("htmlUrl");

        title =   null!=title ? title : text;
        desc =    null!=desc ? desc : title;
        xmlUrl =  null!=xmlUrl ? xmlUrl : url;
        url =     null!=htmlUrl ? htmlUrl : url;
        
        // better to truncate imported OPML fields than to fail import or drop whole bookmark
        int maxLength = RollerConstants.TEXTWIDTH_255;

        if (title != null && title.length() > maxLength) {
            title = title.substring(0,  maxLength);
        }
        if (desc != null && desc.length() > maxLength) {
            desc = desc.substring(0, maxLength);
        }
        if (url != null && url.length() > maxLength) {
            url = url.substring(0, maxLength);
        }
        if (xmlUrl != null && xmlUrl.length() > maxLength) {
            xmlUrl = xmlUrl.substring(0, maxLength);
        }

        if (elem.getChildren().isEmpty()) {
            // Leaf element.  Store a bookmark
            // Currently bookmarks must have at least a name and 
            // HTML url to be stored. Previous logic was
            // trying to skip invalid ones, but was letting ones 
            // with an xml url and no html url through
            // which could result in a db exception.
            if (null != title && null != url) {
                WeblogBookmark bd = new WeblogBookmark(folder,
                        title,
                        desc,
                        url,
                        xmlUrl,
                        null);
                folder.addBookmark(bd);
                this.strategy.store(bd);
            }
        } else {
            // Import suboutline's children into folder
            for (Element subelem : elem.getChildren("outline")) {
                importOpmlElement(subelem, folder );
            }
        }
    }