Java Code Examples for org.apache.xmlbeans.XmlCursor#insertAttributeWithValue()

The following examples show how to use org.apache.xmlbeans.XmlCursor#insertAttributeWithValue() . 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: DefaultEbicsRootElement.java    From ebics-java-client with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
  * Inserts a schema location to the current ebics root element.
  * @param namespaceURI the name space URI
  * @param localPart the local part
  * @param prefix the prefix
  * @param value the value
  */
 public void insertSchemaLocation(String namespaceURI,
                                  String localPart,
                                  String prefix,
                                  String value)
 {
   XmlCursor 			cursor;

   cursor = document.newCursor();
   while (cursor.hasNextToken()) {
     if (cursor.isStart()) {
cursor.toNextToken();
cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
break;
     } else {
cursor.toNextToken();
     }
   }
 }
 
Example 2
Source File: DefaultEbicsRootElement.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Inserts a schema location to the current ebics root element.
 *
 * @param namespaceURI the name space URI
 * @param localPart the local part
 * @param prefix the prefix
 * @param value the value
 */
public void insertSchemaLocation(
    String namespaceURI, String localPart, String prefix, String value) {
  XmlCursor cursor;

  cursor = document.newCursor();
  while (cursor.hasNextToken()) {
    if (cursor.isStart()) {
      cursor.toNextToken();
      cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
      break;
    } else {
      cursor.toNextToken();
    }
  }
}
 
Example 3
Source File: XMLLibImpl.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Escapes the reserved characters in a value of an attribute
 *
 * @param value Unescaped text
 * @return The escaped text
 */
public String escapeAttributeValue(Object value)
{
    String text = ScriptRuntime.toString(value);

    if (text.length() == 0) return "";

    XmlObject xo = XmlObject.Factory.newInstance();

    XmlCursor cursor = xo.newCursor();
    cursor.toNextToken();
    cursor.beginElement("a");
    cursor.insertAttributeWithValue("a", text);
    cursor.dispose();

    String elementText = xo.toString();
    int begin = elementText.indexOf('"');
    int end = elementText.lastIndexOf('"');
    return elementText.substring(begin + 1, end);
}
 
Example 4
Source File: ViisaregisterXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public TaotluseAndmedVastus taotluseAndmedNrLiikParing(String taotluseLiik, String taotluseNr) throws XRoadServiceConsumptionException {
	TaotluseAndmedNrLiikSisend paring = TaotluseAndmedNrLiikSisend.Factory.newInstance();
	paring.setTaotluseLiik(com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.TaotluseLiik.Enum.forString(taotluseLiik));
	paring.setTaotluseNr(taotluseNr);

	//Kuna viisaregister tahab kindlasti oma xsi:type atribuute näha, siis paneme need käsitsi külge
	XmlCursor cursor = paring.newCursor();
	while (!cursor.isEnddoc()) {
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("taotluseLiik")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "ns5:taotluseLiik");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("taotluseNr")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:string");
		}
		cursor.toNextToken();
	}

	return viisaregisterXRoadDatabase.taotlAndmedNrLiikParingV1(paring);
}
 
Example 5
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param attrName
 * @param value
 */
void setAttribute(XMLName xmlName, Object value)
{
    if (xmlName.uri() == null &&
        xmlName.localName().equals("*"))
    {
        throw ScriptRuntime.typeError("@* assignment not supported.");
    }

    XmlCursor curs = newCursor();

    String strValue = ScriptRuntime.toString(value);
    if (curs.currentTokenType().isStartdoc())
    {
        curs.toFirstContentToken();
    }

    javax.xml.namespace.QName qName;

    try
    {
        qName = new javax.xml.namespace.QName(xmlName.uri(), xmlName.localName());
    }
    catch(Exception e)
    {
        throw ScriptRuntime.typeError(e.getMessage());
    }

    if (!curs.setAttributeText(qName, strValue))
    {
        if (curs.currentTokenType().isStart())
        {
            // Can only add attributes inside of a start.
            curs.toNextToken();
        }
        curs.insertAttributeWithValue(qName, strValue);
    }

    curs.dispose();
}
 
Example 6
Source File: XmlBeansUtil.java    From j-road with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new {@link XmlString} instance holding the given <code>String</code> value. The instance will also have an
 * attribute with <code>xsi:type</code> name (where <code>xsi</code> represent a prefix for
 * <code>http://www.w3.org/2001/XMLSchema-instance</code> namespace) and a <code>xsd:string</code> value (where
 * <code>xsd</code> represents a prefix for <code>http://www.w3.org/2001/XMLSchema</code> namespace).
 * 
 * @param value content value
 * @return constructed {@link XmlString} instance
 */
public static XmlString getAttributedXmlString(String value) {
  XmlString xmlString = XmlString.Factory.newInstance();
  xmlString.setStringValue(value);

  XmlCursor cursor = xmlString.newCursor();
  cursor.toNextToken();
  cursor.insertNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
  cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"),
                                  "xsd:string");

  return xmlString;
}
 
Example 7
Source File: TarnXTeeServiceImpl.java    From j-road with Apache License 2.0 4 votes vote down vote up
private void insertTypeAttribute(XmlCursor cursor, String uri, String localPart, String prefix, String type) {
  cursor.insertAttributeWithValue(new QName(uri, localPart, prefix), type);
}
 
Example 8
Source File: ViisaregisterXTeeServiceImpl.java    From j-road with Apache License 2.0 4 votes vote down vote up
public TaotlusteNimistuVastus taotluseAndmedIsikReisidokumentParing(String eesnimi, String perenimi, Calendar synniaeg, String sugu, String reisiDokLiik, String reisiDokNr, Calendar reisiDokValjastamisKuup, String toimik) throws XRoadServiceConsumptionException {
	TaotluseAndmedIsikReisidokSisend paring = TaotluseAndmedIsikReisidokSisend.Factory.newInstance();
	if (eesnimi != null || perenimi != null || synniaeg != null || sugu != null) {
		StruktIsikSuguMK isik = paring.addNewIsik();
		isik.setEesnimi(eesnimi);
		isik.setPerenimi(perenimi);
		isik.setSynniaeg(synniaeg);
		com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.Sugu.Enum suguEnum = com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.Sugu.Enum.forString(sugu);
		isik.setSugu(suguEnum);
	}

	com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.ReisiDokLiik.Enum reisiDokLiikEnum = com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.ReisiDokLiik.Enum.forString(reisiDokLiik);
	paring.setReisiDokLiik(reisiDokLiikEnum);
	paring.setReisiDokNr(reisiDokNr);
	paring.setReisiDokValjastamisKuup(reisiDokValjastamisKuup);

	//Kuna viisaregister tahab kindlasti oma xsi:type atribuute näha, siis paneme need käsitsi külge
	XmlCursor cursor = paring.newCursor();
	while (!cursor.isEnddoc()) {
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("isik")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "ns5:struktIsikSuguMK");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("eesnimi")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:string");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("perenimi")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:string");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("synniaeg")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:date");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("sugu")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "ns5:sugu");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("reisiDokLiik")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "ns5:reisiDokLiik");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("reisiDokNr")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:string");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("reisiDokValjastamisKuup")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:date");
		}
		cursor.toNextToken();
	}

	return viisaregisterXRoadDatabase.taotlAndmedIsikReisidokParingV1(paring);
}
 
Example 9
Source File: SesParser.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
/**
 * build describe sensor request. This was a work-around because the implemented
 * request in the OX-Framework didn't work.
 */
@Deprecated
private synchronized String buildDescribeSensorRequest(ParameterContainer parameter) {
    String ns_addressing = "http://www.w3.org/2005/08/addressing";
    String request = "";
    String ns_ses = "http://www.opengis.net/ses/0.0";

    EnvelopeDocument envDoc = EnvelopeDocument.Factory.newInstance();
    Envelope env = envDoc.addNewEnvelope();
    Header header = env.addNewHeader();
    Body body = env.addNewBody();
    String sesURL = (String)parameter.getParameterShellWithCommonName(ISESRequestBuilder.DESCRIBE_SENSOR_SES_URL).getSpecifiedValue();
    XmlCursor cur = null;

    SESUtils.addNamespacesToEnvelope_000(env);

    cur = header.newCursor();

    cur.toFirstContentToken();
    cur.insertElementWithText(new QName(ns_addressing,"To","wsa"),
            sesURL);
    cur.insertElementWithText(new QName(ns_addressing,"Action","wsa"),
    "http://www.opengis.net/ses/DescribeSensorRequest");
    cur.insertElementWithText(new QName(ns_addressing,"MessageID","wsa"),
            UUID.randomUUID().toString());
    cur.beginElement(new QName(ns_addressing,"From","wsa"));
    cur.insertElementWithText(new QName(ns_addressing,"Address","wsa"),
    "http://www.w3.org/2005/08/addressing/role/anonymous");
    cur.dispose();

    cur = body.newCursor();

    cur.toFirstContentToken();
    cur.beginElement(new QName(ns_ses,"DescribeSensor","ses"));
    cur.insertAttributeWithValue("service","SES");
    cur.insertAttributeWithValue("version", "1.0.0");
    cur.insertElementWithText(new QName(ns_ses,"SensorID","ses"), 
            (String)parameter.getParameterShellWithCommonName(ISESRequestBuilder.DESCRIBE_SENSOR_SENSOR_ID).getSpecifiedValue());
    cur.dispose();

    request = envDoc.xmlText();

    return request;
}