Java Code Examples for org.xmlpull.v1.XmlPullParser#isEmptyElementTag()

The following examples show how to use org.xmlpull.v1.XmlPullParser#isEmptyElementTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YahooXmlParser.java    From Equate with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Iterates through each "resource" tag in the "resources" parent. Each
 * currency should have it's own "resource" tag.
 */
private HashMap<String, Entry> readListOfResources(XmlPullParser parser)
		  throws XmlPullParserException, IOException {
	HashMap<String, Entry> entries = new HashMap<>();

	parser.require(XmlPullParser.START_TAG, ns, "resources");
	while (parser.next() != XmlPullParser.END_TAG) {
		if (parser.getEventType() != XmlPullParser.START_TAG){
			continue;
		}
		String name = parser.getName();
		// Starts by looking for the resource tag
		if (name.equals("resource")){
			if (parser.isEmptyElementTag()){
				skip(parser);
			}
			Entry ent = readResource(parser);
			if (ent != null){
				entries.put(ent.symbol, ent);
			}
		} else {
			skip(parser);
		}
	}
	return entries;
}
 
Example 2
Source File: RepositoryXmlParser.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Resource parseReqsAndCaps(XmlPullParser p) throws Exception {
  if (p.isEmptyElementTag()) {
    p.next();
    return null;
  }
  ResourceImpl r = new ResourceImpl();
  int startDepth = p.getDepth();
  p.next();
  while( !(p.getEventType() == XmlPullParser.END_DOCUMENT)
      && !(p.getEventType() == XmlPullParser.END_TAG 
      && p.getDepth() == startDepth)) {
    if (p.getEventType() != XmlPullParser.START_TAG) {
      p.next();
      continue;
    } 
    if ("requirement".equalsIgnoreCase(p.getName())) {
      RequirementImpl req = parseReq(p);
      if(req != null) {
        req.d.resource = r;
        r.addReq(req);
      }
      p.next();
      continue;
    }
    if ("capability".equalsIgnoreCase(p.getName())) {
      CapabilityImpl cap = parseCap(p);
      if(cap != null) {
        cap.d.resource = r;
        r.addCap(cap);
      }
      p.next();
      continue;
    }
  }
  return r;
}
 
Example 3
Source File: RepositoryXmlParser.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Data parseData(XmlPullParser p) throws Exception {
  Data d = new Data(p.getAttributeCount() == 1 && "namespace".equals(p.getAttributeName(0))
                    ? p.getAttributeValue(0) : "");
  if (p.isEmptyElementTag()) {
    p.next(); // We still get an END_TAG
    return d;
  }
  int startDepth = p.getDepth();
  p.next();
  while( !(p.getEventType() == XmlPullParser.END_DOCUMENT)
      && !(p.getEventType() == XmlPullParser.END_TAG 
      && p.getDepth() == startDepth)) {
    if (p.getEventType() != XmlPullParser.START_TAG) {
      p.next();
      continue;
    }
    if ("attribute".equalsIgnoreCase(p.getName())) {
      parseAttribute(p, d);
      p.next();
      continue;
    }
    if ("directive".equalsIgnoreCase(p.getName())) {
      parseDirective(p, d);
      p.next();
      continue;
    }
  }
  return d;
}
 
Example 4
Source File: KmlStyleParser.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the hot spot for the icon
 *
 * @param style Style object to apply hotspot properties to
 */
private static void setIconHotSpot(XmlPullParser parser, KmlStyle style)
        throws XmlPullParserException {
    if (parser.isEmptyElementTag()) {
        return;
    }
    float xValue, yValue;
    String xUnits, yUnits;
    xValue = Float.parseFloat(parser.getAttributeValue(null, "x"));
    yValue = Float.parseFloat(parser.getAttributeValue(null, "y"));
    xUnits = parser.getAttributeValue(null, "xunits");
    yUnits = parser.getAttributeValue(null, "yunits");
    style.setHotSpot(xValue, yValue, xUnits, yUnits);
}
 
Example 5
Source File: TransitionInflater.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private Transition createTransitionFromXml(XmlPullParser parser,
        AttributeSet attrs, Transition parent)
        throws XmlPullParserException, IOException {

    Transition transition = null;

    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();

    TransitionSet transitionSet = (parent instanceof TransitionSet)
            ? (TransitionSet) parent : null;

    while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String  name = parser.getName();
        if ("fade".equals(name)) {
            transition = new Fade(mContext, attrs);
        } else if ("changeBounds".equals(name)) {
            transition = new ChangeBounds(mContext, attrs);
        } else if ("slide".equals(name)) {
            transition = new Slide(mContext, attrs);
        } else if ("explode".equals(name)) {
            transition = new Explode(mContext, attrs);
        } else if ("changeImageTransform".equals(name)) {
            transition = new ChangeImageTransform(mContext, attrs);
        } else if ("changeTransform".equals(name)) {
            transition = new ChangeTransform(mContext, attrs);
        } else if ("changeClipBounds".equals(name)) {
            transition = new ChangeClipBounds(mContext, attrs);
        } else if ("autoTransition".equals(name)) {
            transition = new AutoTransition(mContext, attrs);
        } else if ("recolor".equals(name)) {
            transition = new Recolor(mContext, attrs);
        } else if ("changeScroll".equals(name)) {
            transition = new ChangeScroll(mContext, attrs);
        } else if ("transitionSet".equals(name)) {
            transition = new TransitionSet(mContext, attrs);
        } else if ("transition".equals(name)) {
            transition = (Transition) createCustom(attrs, Transition.class, "transition");
        } else if ("targets".equals(name)) {
            getTargetIds(parser, attrs, parent);
        } else if ("arcMotion".equals(name)) {
            parent.setPathMotion(new ArcMotion(mContext, attrs));
        } else if ("pathMotion".equals(name)) {
            parent.setPathMotion((PathMotion)createCustom(attrs, PathMotion.class, "pathMotion"));
        } else if ("patternPathMotion".equals(name)) {
            parent.setPathMotion(new PatternPathMotion(mContext, attrs));
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
        if (transition != null) {
            if (!parser.isEmptyElementTag()) {
                createTransitionFromXml(parser, attrs, transition);
            }
            if (transitionSet != null) {
                transitionSet.addTransition(transition);
                transition = null;
            } else if (parent != null) {
                throw new InflateException("Could not add transition to another transition.");
            }
        }
    }

    return transition;
}
 
Example 6
Source File: PacketParserUtils.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a packet extension sub-packet.
 *
 * @param elementName the XML element name of the packet extension.
 * @param namespace the XML namespace of the packet extension.
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser)
        throws Exception
{
    // See if a provider is registered to handle the extension.
    Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace);
    if (provider != null) {
        if (provider instanceof PacketExtensionProvider) {
            return ((PacketExtensionProvider)provider).parseExtension(parser);
        }
        else if (provider instanceof Class) {
            return (PacketExtension)parseWithIntrospection(
                    elementName, (Class)provider, parser);
        }
    }
    // No providers registered, so use a default extension.
    DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            String name = parser.getName();
            // If an empty element, set the value with the empty string.
            if (parser.isEmptyElementTag()) {
                extension.setValue(name,"");
            }
            // Otherwise, get the the element text.
            else {
                eventType = parser.next();
                if (eventType == XmlPullParser.TEXT) {
                    String value = parser.getText();
                    extension.setValue(name, value);
                }
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(elementName)) {
                done = true;
            }
        }
    }
    return extension;
}
 
Example 7
Source File: TransitionInflater.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
@Nullable
private Transition createTransitionFromXml(@NonNull XmlPullParser parser,
                                           @NonNull AttributeSet attrs,
                                           @Nullable Transition parent)
        throws XmlPullParserException, IOException {

    Transition transition = null;

    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();

    TransitionSet transitionSet = (parent instanceof TransitionSet)
            ? (TransitionSet) parent : null;

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String  name = parser.getName();
        if ("fade".equals(name)) {
            transition = new Fade(mContext, attrs);
        } else if ("changeBounds".equals(name)) {
            transition = new ChangeBounds(mContext, attrs);
        } else if ("slide".equals(name)) {
            transition = new Slide(mContext, attrs);
        } else if ("explode".equals(name)) {
            transition = new Explode(mContext, attrs);
        } else if ("changeImageTransform".equals(name)) {
            transition = new ChangeImageTransform(mContext, attrs);
        } else if ("changeTransform".equals(name)) {
            transition = new ChangeTransform(mContext, attrs);
        } else if ("changeClipBounds".equals(name)) {
            transition = new ChangeClipBounds(mContext, attrs);
        } else if ("autoTransition".equals(name)) {
            transition = new AutoTransition(mContext, attrs);
        } else if ("recolor".equals(name)) {
            transition = new Recolor(mContext, attrs);
        } else if ("changeScroll".equals(name)) {
            transition = new ChangeScroll(mContext, attrs);
        } else if ("transitionSet".equals(name)) {
            transition = new TransitionSet(mContext, attrs);
        } else if ("scale".equals(name)) {
            transition = new Scale(mContext, attrs);
        } else if ("translation".equals(name)) {
            transition = new TranslationTransition(mContext, attrs);
        } else if ("transition".equals(name)) {
            transition = (Transition) createCustom(attrs, Transition.class, "transition");
        } else if ("targets".equals(name) && parent != null) {
            getTargetIds(parser, attrs, parent);
        } else if ("arcMotion".equals(name) && parent != null) {
            parent.setPathMotion(new ArcMotion(mContext, attrs));
        } else if ("pathMotion".equals(name) && parent != null) {
            parent.setPathMotion((PathMotion)createCustom(attrs, PathMotion.class, "pathMotion"));
        } else if ("patternPathMotion".equals(name) && parent != null) {
            parent.setPathMotion(new PatternPathMotion(mContext, attrs));
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
        if (transition != null) {
            if (!parser.isEmptyElementTag()) {
                createTransitionFromXml(parser, attrs, transition);
            }
            if (transitionSet != null) {
                transitionSet.addTransition(transition);
                transition = null;
            } else if (parent != null) {
                throw new InflateException("Could not add transition to another transition.");
            }
        }
    }

    return transition;
}