Example usage for org.xml.sax Attributes getValue

List of usage examples for org.xml.sax Attributes getValue

Introduction

In this page you can find the example usage for org.xml.sax Attributes getValue.

Prototype

public abstract String getValue(String qName);

Source Link

Document

Look up an attribute's value by XML qualified (prefixed) name.

Usage

From source file:de.laeubisoft.tools.ant.validation.W3CMarkupValidationTask.java

/**
 * Takes an {@link URL} and tries to find out all linked resources
 * //w w w. j av  a  2  s.  com
 * @param uriToRecurse
 * @return a set of discovered urls
 */
private Set<URL> recurseInto(final URL uriToRecurse) throws BuildException {
    final Set<URL> urlsFound = new HashSet<URL>();
    XMLReader reader = new Parser();
    reader.setContentHandler(new DefaultHandler() {
        @Override
        public void startElement(String nsuri, String localName, String qName, Attributes attributes)
                throws SAXException {
            if ("a".equalsIgnoreCase(qName)) {
                String value = attributes.getValue("href");
                if (value != null) {
                    try {
                        URL url = new URL(uriToRecurse, value);
                        if (url.getHost().equalsIgnoreCase(uriToRecurse.getHost())
                                && url.getPort() == uriToRecurse.getPort()) {
                            urlsFound.add(url);
                        }
                    } catch (MalformedURLException e) {
                        log("can't parse URL for href = " + value + ", it will be ignored!", Project.MSG_ERR);
                    }
                }
            }
        }
    });
    // Parsen wird gestartet
    try {
        reader.parse(new InputSource(uriToRecurse.openStream()));
        return urlsFound;
    } catch (IOException e) {
        throw new BuildException("error while accessing data at " + uriToRecurse, e);
    } catch (SAXException e) {
        throw new BuildException("error while parsing data at " + uriToRecurse, e);
    }
}

From source file:net.bible.service.format.osistohtml.strongs.StrongsHandler.java

public void start(Attributes attrs) {
    if ((parameters.isShowStrongs() || parameters.isShowMorphology())
            && TagHandlerHelper.isAttr(OSISUtil.ATTRIBUTE_W_LEMMA, attrs)) {
        // Strongs & morphology references
        // example of strongs refs: <w lemma="strong:H0430">God</w> <w lemma="strong:H0853 strong:H01254" morph="strongMorph:TH8804">created</w>
        // better example, because we just use Robinson: <w lemma="strong:G652" morph="robinson:N-NSM" src="2">an apostle</w>
        String strongsLemma = attrs.getValue(OSISUtil.ATTRIBUTE_W_LEMMA);
        if (strongsLemma.startsWith(OSISUtil.LEMMA_STRONGS)) {
            String morphology = attrs.getValue(OSISUtil.ATTRIBUTE_W_MORPH);
            pendingStrongsAndMorphTags = getStrongsAndMorphTags(strongsLemma, morphology);
        }//from   ww  w  . j  a va  2s .  c om
    }
}

From source file:com.aurel.track.exchange.docx.importer.HTMLParser.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (qName.equalsIgnoreCase(ELEMENT_NAME.STYLE.getElementName())) {
        insideStyle = true;//from   www . j  av  a2s .com
        contentBuffer = new StringBuilder();
    } else {
        if (qName.equalsIgnoreCase(ELEMENT_NAME.P.getElementName())) {
            String clazz = attributes.getValue(ATTRIBUTE_NAME.CLASS.getElementName());
            if (clazz != null && !"".equals(clazz)) {
                if (clazz.contains(localizedHeading)) {
                    for (int i = 1; i <= MAX_HEADING_LEVEL; i++) {
                        if (clazz.contains(localizedHeading + i)) {
                            if (insideContent) {
                                //not the first heading: add the gathered description of the previous item when the new heading begins
                                currentNode.setDescription(contentBuffer.toString());
                            }
                            currentNode = new ItemNode();
                            //currentNode.setElementType(ELEMENT_NAME.HEADING);
                            currentNode.setHeadingLevel(i);
                            if (!stack.isEmpty()) {
                                ItemNode itemNode = stack.peek();
                                if (i > itemNode.getHeadingLevel()) {
                                    //current heading level > stack heading level: first sub-chapter
                                    List<ItemNode> children = itemNode.getChildren();
                                    if (children == null) {
                                        children = new ArrayList<ItemNode>();
                                        itemNode.setChildren(children);
                                    }
                                    //add as child to the peek
                                    children.add(currentNode);
                                } else {
                                    if (i == itemNode.getHeadingLevel()) {
                                        //sibling sub-chapter: remove sibling
                                        itemNode = stack.pop();
                                        //get the parent chapter
                                        itemNode = stack.peek();
                                        List<ItemNode> children = itemNode.getChildren();
                                        if (children == null) {
                                            //should never happen
                                            children = new ArrayList<ItemNode>();
                                            itemNode.setChildren(children);
                                        }
                                        //add as child to the peek
                                        children.add(currentNode);
                                    } else {
                                        if (i < itemNode.getHeadingLevel()) {
                                            //new parent chapter starts
                                            while (!stack.isEmpty()) {
                                                //remove all children/descendants of the new parent's previous sibling
                                                itemNode = stack.pop();
                                                if (itemNode.getHeadingLevel() == i) {
                                                    break;
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                            if (stack.isEmpty()) {
                                htmlContent.getChapters().add(currentNode);
                            }
                            stack.push(currentNode);
                            insideHeadingParagraph = true;
                            insideContent = true;
                            //gather the paragraph title
                            contentBuffer = new StringBuilder();
                            break;
                        }
                    }
                }
            }
        }
    }

    if (insideContent && !insideHeadingParagraph) {
        //gather the description content
        String eName = localName; // element name
        if ("".equals(eName)) {
            eName = qName; // not namespaceAware
        }
        contentBuffer.append("<" + eName);
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                String aName = attributes.getLocalName(i); // Attr name 
                if ("".equals(aName)) {
                    aName = attributes.getQName(i);
                }
                contentBuffer.append(" ");
                contentBuffer.append(aName + "=\"" + attributes.getValue(i) + "\"");
            }
        }
        contentBuffer.append(">");
    }

}

From source file:com.liusoft.sc.startup.WebRuleSet.java

public void begin(String namespace, String name, Attributes attributes) throws Exception {
    Context context = (Context) digester.peek(digester.getCount() - 1);
    String value = attributes.getValue("metadata-complete");
    if ("true".equals(value)) {
        context.setIgnoreAnnotations(true);
    } else if ("false".equals(value)) {
        context.setIgnoreAnnotations(false);
    }//from  w w  w  .ja va 2s . com
    if (digester.getLogger().isDebugEnabled()) {
        digester.getLogger().debug(context.getClass().getName() + ".setIgnoreAnnotations( "
                + context.getIgnoreAnnotations() + ")");
    }
}

From source file:com.autentia.tnt.manager.report.ReportManager.java

public void startElement(String uri, String localName, String tagName, Attributes attributes)
        throws SAXException {
    log.debug("parseDocument -   startElement(" + tagName + ")=" + (System.currentTimeMillis() - parsingStart)
            + " ms.");
    tempVal = "";
    if (tagName.equals("parameter")) {
        tempParam = new ParameterReport();
        tempParam.setName(attributes.getValue("name"));
    } else if ((tagName.equals("queryString")) || (tagName.equals("background"))) {
        throw new FinalizeParsingException("Finalize parsing jrxml");
    }//from   w  w  w . j  av a  2  s. c o  m
}

From source file:ch.entwine.weblounge.common.impl.content.AbstractResourceReaderImpl.java

/**
 * The parser found the start of an element. Information about this element as
 * well as the attached attributes are passed to this method.
 * /*from  w  w  w .j a  v  a2  s  .  c o m*/
 * @param uri
 *          information about the namespace
 * @param local
 *          the local name of the element
 * @param raw
 *          the raw name of the element
 * @param attrs
 *          the element's attributes
 */
@Override
public void startElement(String uri, String local, String raw, Attributes attrs) throws SAXException {

    // read the page url
    if (rootTag.equals(raw)) {
        parserContext = ParserContext.Resource;
        resource.getURI().setType(rootTag);
        resource.getURI().setIdentifier(attrs.getValue("id"));
        if (StringUtils.isNotBlank(attrs.getValue("path")))
            resource.getURI().setPath(attrs.getValue("path"));
        if (StringUtils.isNotBlank(attrs.getValue("version"))) {
            long version = ResourceUtils.getVersion(attrs.getValue("version"));
            resource.getURI().setVersion(version);
        }
    }

    // in the header
    else if ("head".equals(raw)) {
        parserContext = ParserContext.Head;
    }

    // in the body
    else if ("body".equals(raw)) {
        parserContext = ParserContext.Body;
    }

    if (readHeader) {

        // title, subject and the like
        if ("title".equals(raw) || "subject".equals(raw) || "description".equals(raw) || "coverage".equals(raw)
                || "rights".equals(raw)) {
            String language = attrs.getValue("language");
            if (language != null) {
                Language l = LanguageUtils.getLanguage(language);
                clipboard.put("language", l);
            } else {
                clipboard.remove("language");
            }
        }

    }

    super.startElement(uri, local, raw, attrs);

}

From source file:info.magnolia.about.app.AboutPresenter.java

String[] getConnectionString() {
    File config = null;/*ww w . ja v a 2 s. c  o  m*/
    // Assuming, the path to the repository-config.-file is configured relative, starting with WEB-INF.
    // Otherwise, assuming it's an absolute path for this config. (See JIRA MGNLUI-3163)
    String configuredPath = magnoliaProperties.getProperty("magnolia.repositories.jackrabbit.config");
    if (configuredPath != null) {
        if (configuredPath.startsWith("WEB-INF")) {
            config = new File(magnoliaProperties.getProperty("magnolia.app.rootdir") + "/" + configuredPath);
        } else {
            config = new File(configuredPath);
        }
    }
    // No special handling here if the config (file) is null or not existing.
    // If the path is wrong or not set, Magnolia won't start up properly and it won't be possible to launch the About-app.

    final String[] connectionString = new String[3];
    try {
        SAXParserFactory.newInstance().newSAXParser().parse(config, new DefaultHandler() {
            private boolean inPM;

            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes)
                    throws SAXException {
                super.startElement(uri, localName, qName, attributes);
                if ("PersistenceManager".equals(qName) || "DataSource".equals(qName)) {
                    inPM = true;
                }
                if (inPM && "param".equals(qName)) {
                    if ("url".equals(attributes.getValue("name"))) {
                        connectionString[0] = attributes.getValue("value");
                    }
                    if ("user".equals(attributes.getValue("name"))) {
                        connectionString[1] = attributes.getValue("value");
                    }
                    if ("password".equals(attributes.getValue("name"))) {
                        connectionString[2] = attributes.getValue("value");
                    }
                }
            }

            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                super.endElement(uri, localName, qName);
                if ("PersistenceManager".equals(localName) || "DataSource".equals(qName)) {
                    inPM = false;
                }
            }
        });
        return connectionString;
    } catch (Exception e) {
        log.debug("Failed to obtain DB connection info with {}", e.getMessage(), e);
    }
    return null;
}

From source file:io.inkstand.jcr.util.JCRContentHandler.java

/**
 * Creates the {@link Node} in the repository from the given attributes
 *
 * @param parent    inkstand.jcr.config - the absolute path to your configuration file for the cluster node
inkstand.jcr.home - the absolute path to the working directory of the cluster node
        //from  w ww.j  av  a  2  s . co m
More on Jackrabbit configuration can be found on the Apache Jackrabbit project page.
 *         the parent node of the node to be created. If this is null, a root-level node will be created.
 * @param attributes
 *         the attributes containing the basic information required to create the node
 *
 * @return the newly creates {@link Node}
 *
 * @throws RepositoryException
 */
private Node newNode(final Node parent, final Attributes attributes) throws RepositoryException {

    Node parentNode;
    if (parent == null) {
        parentNode = session.getRootNode();
    } else {
        parentNode = parent;
    }
    // TODO handle path parameters

    final String name = attributes.getValue("name");
    final String primaryType = attributes.getValue("primaryType");

    LOG.info("Node {} adding child node {}(type={})", parentNode.getPath(), name, primaryType);
    return parentNode.addNode(name, primaryType);
}

From source file:com.frostwire.gui.updates.UpdateMessageReader.java

public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    // deal with the opening tag
    if (localName.equalsIgnoreCase("update")) {
        UpdateManager.getInstance().setServerTime(atts.getValue("time"));

        if (atts.getValue("torrentDetailsUrl") != null && atts.getValue("torrentDetailsUrl").length() > 0) {
            String torrentDetailsUrl = atts.getValue("torrentDetailsUrl");

            List<SearchEngine> searchEngines = SearchEngine.getSearchEngines();
            for (SearchEngine searchEngine : searchEngines) {
                // not doing it for ClearBits on purpose.
                if (!searchEngine.equals(SearchEngine.CLEARBITS)) {
                    searchEngine.redirectUrl = torrentDetailsUrl;
                }//from  ww w.j a  va 2s  .  c om
            }
        }
    } else if (localName.equalsIgnoreCase("message")) {
        String type = atts.getValue("type");
        String message = atts.getValue("value");
        String url = atts.getValue("url");
        String torrent = atts.getValue("torrent");
        String installerUrl = atts.getValue("installerUrl");
        String os = atts.getValue("os");
        String showOnce = atts.getValue("showOnce");
        String version = atts.getValue("version");
        String src = atts.getValue("src");

        _bufferMessage = new UpdateMessage(type, message);
        _bufferMessage.setUrl(url);
        _bufferMessage.setTorrent(torrent);
        _bufferMessage.setInstallerUrl(installerUrl);
        _bufferMessage.setOs(os);
        _bufferMessage.setShowOnce(showOnce);
        _bufferMessage.setVersion(version);

        if (atts.getValue("md5") != null) {
            _bufferMessage.setRemoteMD5(atts.getValue("md5"));
            LOG.debug("UpdateMessageReader.startElement overlay md5=" + atts.getValue("md5"));
        }

        // language properties available only inside overlay
        if (atts.getValue("language") != null) {
            _bufferMessage.setLanguage(atts.getValue("language"));
            // System.out.println("UpdateMessageReader.startElement overlay language="
            // + atts.getValue("lang"));
        }

        if (atts.getValue("valueInstallerReady") != null) {
            _bufferMessage.setMessageInstallerReady(atts.getValue("valueInstallerReady"));
            // System.out.println("UpdateMessageReader.startElement overlay md5="
            // + atts.getValue("md5"));
        }

        if (_bufferMessage.getMessageType().equalsIgnoreCase("announcement")) {
            _bufferMessage.setExpiration(atts.getValue("expiration"));
        }

        if (_bufferMessage.getMessageType().equalsIgnoreCase("chat_server")) {
            ChatSettings.CHAT_SERVER.setValue(message);
            ChatSettings.instance().save();
        }

        // deal with overlay messages specific properties
        if (_bufferMessage.getMessageType().equalsIgnoreCase("overlay")) {
            // System.out.println("UpdateMessageReader.startElement overlay msg found");
            _bufferMessage.setSrc(src);

            if (atts.getValue("intro") != null
                    && (atts.getValue("intro").equals("1") || atts.getValue("intro").equalsIgnoreCase("true")
                            || atts.getValue("intro").equalsIgnoreCase("yes"))) {
                _bufferMessage.setIntro(true);
                // System.out.println("UpdateMessageReader.startElement overlay intro=true");
            } else {
                _bufferMessage.setIntro(false);
                // System.out.println("UpdateMessageReader.startElement overlay intro=false");
            }
        } // overlays

    }

}

From source file:edu.ku.brc.specify.toycode.mexconabio.FMPCreateTable.java

public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) {
    buffer.setLength(0);//from  w  w w  .  ja  va 2  s .  c  o  m

    if (localName.equals("FIELD")) {
        FieldDef fldDef = new FieldDef();
        fields.add(fldDef);

        for (int i = 0; i < attrs.getLength(); i++) {
            String attr = attrs.getLocalName(i);
            String value = attrs.getValue(i);
            if (attr.equals("EMPTYOK")) {
                fldDef.setNullable(value.equals("YES"));

            } else if (attr.equals("NAME")) {
                value = StringUtils.capitalize(value.trim());
                value = StringUtils.deleteWhitespace(value);
                value = StringUtils.replace(value, "_", "");

                if ((value.charAt(0) >= '0' && value.charAt(0) <= '9') || value.equalsIgnoreCase("New")
                        || value.equalsIgnoreCase("Group")) {
                    value = "Fld" + value;
                }

                String fixedStr = convertFromTwoByteUTF8(value);
                fixedStr = StringUtils.replace(fixedStr, ".", "");
                fixedStr = StringUtils.replace(fixedStr, ":", "");
                fixedStr = StringUtils.replace(fixedStr, "/", "_");
                fldDef.setName(fixedStr);
                fldDef.setOrigName(value);

            } else if (attr.equals("TYPE")) {
                if (value.equals("TEXT")) {
                    fldDef.setType(DataType.eText);

                } else if (value.equals("NUMBER")) {
                    fldDef.setType(DataType.eNumber);

                } else if (value.equals("DATE")) {
                    fldDef.setType(DataType.eDate);

                } else if (value.equals("TIME")) {
                    fldDef.setType(DataType.eTime);
                } else {
                    System.err.println("Unknown Type[" + value + "]");
                }
            }
        }
    }
}