Java Code Examples for org.dom4j.Element#attributeValue()

The following examples show how to use org.dom4j.Element#attributeValue() . 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: ManifestFileUtils.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void singleProcess(Document document, String applicationId) {
        List<Node> nodes = document.getRootElement().selectNodes("//provider");
    for (Node node : nodes) {
        Element element = (Element)node;
        String value = element.attributeValue("name");
        if (value.equals(INSTANT_RUN_CONTENTPROVIDER)){
            element.addAttribute("name",ALI_INSTANT_RUN_CONTENTPROVIDER);
            element.addAttribute("authorities",applicationId+"."+ALI_INSTANT_RUN_CONTENTPROVIDER);
            Attribute attribute = element.attribute("multiprocess");
            if (attribute!= null) {
                attribute.setValue("false");
                logger.warn("singleProcess  com.android.tools.ir.server.InstantRunContentProvider.......");
            }

        }

    }

}
 
Example 2
Source File: LinksPortlet.java    From olat with Apache License 2.0 5 votes vote down vote up
private void init() {
private static final Logger log = LoggerHelper.getLogger();

	if (log.isDebugEnabled()) {
		log.debug("START: Loading remote portlets content.");
	}

	final File configurationFile = new File(WebappHelper.getContextRoot() + CONFIG_FILE);

	// this map contains the whole data
	final HashMap<String, PortletInstitution> portletMap = new HashMap<String, PortletInstitution>();

	final SAXReader reader = new SAXReader();
	try {
		final Document doc = reader.read(configurationFile);
		final Element rootElement = doc.getRootElement();
		final List<Element> lstInst = rootElement.elements(ELEM_INSTITUTION);
		for (final Element instElem : lstInst) {
			final String inst = instElem.attributeValue(ATTR_INSTITUTION_NAME);
			final List<Element> lstTmpLinks = instElem.elements(ELEM_LINK);
			final List<PortletLink> lstLinks = new ArrayList<PortletLink>(lstTmpLinks.size());
			for (final Element linkElem : lstTmpLinks) {
				final String title = linkElem.elementText(ELEM_LINK_TITLE);
				final String url = linkElem.elementText(ELEM_LINK_URL);
				final String target = linkElem.elementText(ELEM_LINK_TARGET);
				final String lang = linkElem.elementText(ELEM_LINK_LANG);
				final String desc = linkElem.elementText(ELEM_LINK_DESC);
				lstLinks.add(new PortletLink(title, url, target, lang, desc));
			}
			portletMap.put(inst, new PortletInstitution(inst, lstLinks));
		}
	} catch (final Exception e) {
		log.error("Error reading configuration file", e);
	} finally {
		content = portletMap;
	}
}
 
Example 3
Source File: Application.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
private void parseCommand(Element root) throws Exception
{
    int code = -1 ;
    try
    {
        if(null!=root.attribute("code")) code = Integer.parseInt(root.attributeValue("code"));
        else
        {
            Dictionary.traceWarning("No commands.code, skipping");
            return ;
        }
    }
    catch(Exception e)
    {
        Dictionary.traceWarning("Invalid command.code, skipping");
        return ;
    }
    
    VendorDef vendor_id = null ;
    if(null != root.attributeValue("vendor-id")) Dictionary.getInstance().getVendorDefByName(root.attributeValue("vendor-id"), _name);
    
    String name = null ;
    if( null != root.attributeValue("name")) name = root.attributeValue("name");
    else
    {
        Dictionary.traceWarning("Invalid command.name, skipping");
        return;
    }
    
    CommandDef commandDef = new CommandDef(code, name, vendor_id);
    
    if(null != getCommandDefByCode(code)) Dictionary.traceWarning("CommandDef of code " + code + " already exists, overwriting");
    if(null != getCommandDefByName(name)) Dictionary.traceWarning("CommandDef of name " + name + " already exists, overwriting");
    
    commandDefByName.put(name, commandDef);
    commandDefByCode.put(Integer.toString(code), commandDef);
}
 
Example 4
Source File: AbstractComponentLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void loadAction(ActionOwner component, Element element) {
    String actionId = element.attributeValue("action");
    if (!StringUtils.isEmpty(actionId)) {
        ComponentContext componentContext = getComponentContext();
        componentContext.addPostInitTask(
                new ActionOwnerAssignActionPostInitTask(component, actionId, componentContext.getFrame())
        );
    }
}
 
Example 5
Source File: Fetcher.java    From githubOfflineInstaller with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前的版本号
 * @return
 * @throws DocumentException
 */
private void fetchVersion(InputStream in){
    try {
        SAXReader reader = new SAXReader();
        Document document = reader.read(in);
        in.close();

        Element rootElement = document.getRootElement();

        List<Element> assemblyElements = rootElement.elements("assemblyIdentity");

        if (assemblyElements.size() == 0) {
            throw new IllegalStateException("Can't get the github version from Github.application");
        }

        for (Element element : assemblyElements) {
            if ("GitHub.application".equals(element.attributeValue("name"))) {
                String version = element.attributeValue("version");
                if (version != null) {
                    this.version = version.replaceAll("\\.", "_");//将版本号变成下划线连接,如3.1.1.4-->3_1_1_4
                    return;
                }
            }
        }
    }catch (Exception e){
        e.printStackTrace();
        throw new IllegalStateException("Can't get the github version from Github.application");
    }
}
 
Example 6
Source File: DsContextLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected MetaClass loadMetaClass(Element element) {
    final String className = element.attributeValue("class");
    if (className == null)
        return null;

    final Class<?> aClass = ReflectionHelper.getClass(className);
    final MetaClass metaClass = metadata.getSession().getClass(aClass);

    if (metaClass == null)
        throw new IllegalStateException(String.format("Can't find metaClass '%s'", className));

    return metaClass;
}
 
Example 7
Source File: AbstractComponentLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Optional<CollectionContainer> loadOptionsContainer(Element element) {
    String containerId = element.attributeValue("optionsContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        if (!(container instanceof CollectionContainer)) {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        return Optional.of((CollectionContainer) container);
    }

    return Optional.empty();
}
 
Example 8
Source File: AbstractFieldLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void loadDatatype(HasDatatype component, Element element) {
    String datatypeAttribute = element.attributeValue("datatype");
    if (StringUtils.isNotEmpty(datatypeAttribute)) {
        //noinspection unchecked
        component.setDatatype(Datatypes.get(datatypeAttribute));
    }
}
 
Example 9
Source File: ServerDialback.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the key sent by a Receiving Server. This server will be acting as the
 * Authoritative Server when executing this method. The remote server may have established
 * a new connection to the Authoritative Server (i.e. this server) for verifying the key
 * or it may be reusing an existing incoming connection.
 *
 * @param doc the Element that contains the key to verify.
 * @param connection the connection to use for sending the verification result
 * @return true if the key was verified.
 */
public static boolean verifyReceivedKey(Element doc, Connection connection) {
    String verifyFROM = doc.attributeValue("from");
    String verifyTO = doc.attributeValue("to");
    String key = doc.getTextTrim();
    StreamID streamID = BasicStreamIDFactory.createStreamID( doc.attributeValue("id") );

    final Logger log = LoggerFactory.getLogger( Log.getName() + "[Acting as Authoritative Server: Verify key sent by RS: " + verifyFROM + " (id " + streamID+ ")]" );

    log.debug( "Verifying key... ");

    // TODO If the value of the 'to' address does not match a recognized hostname,
    // then generate a <host-unknown/> stream error condition
    // TODO If the value of the 'from' address does not match the hostname
    // represented by the Receiving Server when opening the TCP connection, then
    // generate an <invalid-from/> stream error condition

    // Verify the received key
    // Created the expected key based on the received ID value and the shared secret
    String expectedKey = AuthFactory.createDigest(streamID.getID(), getSecretkey());
    boolean verified = expectedKey.equals(key);

    // Send the result of the key verification
    StringBuilder sb = new StringBuilder();
    sb.append("<db:verify");
    sb.append(" from=\"").append(verifyTO).append("\"");
    sb.append(" to=\"").append(verifyFROM).append("\"");
    sb.append(" type=\"");
    sb.append(verified ? "valid" : "invalid");
    sb.append("\" id=\"").append(streamID.getID()).append("\"/>");
    connection.deliverRawText(sb.toString());
    log.debug("Verification successful! Key was: " + (verified ? "VALID" : "INVALID"));
    return verified;
}
 
Example 10
Source File: NotificationFacetProvider.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void loadPosition(NotificationFacet facet, Element element) {
    String position = element.attributeValue("position");
    if (isNotEmpty(position)) {
        facet.setPosition(Position.valueOf(position));
    }
}
 
Example 11
Source File: StudentSectioningXMLLoader.java    From cpsolver with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Load data from the given XML root
 * @param root document root
 * @throws DocumentException
 */
protected void load(Element root) throws DocumentException {
    sLogger.debug("Root element: " + root.getName());
    if (!"sectioning".equals(root.getName())) {
        sLogger.error("Given XML file is not student sectioning problem.");
        return;
    }
    
    if (iLoadOfferings && getModel().getDistanceConflict() != null && root.element("travel-times") != null)
        loadTravelTimes(root.element("travel-times"), getModel().getDistanceConflict().getDistanceMetric());
    
    Map<Long, Placement> timetable = null;
    if (iTimetableFile != null) {
        sLogger.info("Reading timetable from " + iTimetableFile + " ...");
        Document timetableDocument = (new SAXReader()).read(iTimetableFile);
        Element timetableRoot = timetableDocument.getRootElement();
        if (!"timetable".equals(timetableRoot.getName())) {
            sLogger.error("Given XML file is not course timetabling problem.");
            return;
        }
        timetable = loadTimetable(timetableRoot);
    }

    Progress.getInstance(getModel()).load(root, true);
    Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");

    if (root.attributeValue("term") != null)
        getModel().getProperties().setProperty("Data.Term", root.attributeValue("term"));
    if (root.attributeValue("year") != null)
        getModel().getProperties().setProperty("Data.Year", root.attributeValue("year"));
    if (root.attributeValue("initiative") != null)
        getModel().getProperties().setProperty("Data.Initiative", root.attributeValue("initiative"));

    Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
    Map<Long, Course> courseTable = new HashMap<Long, Course>();

    if (iLoadOfferings && root.element("offerings") != null) {
        loadOfferings(root.element("offerings"), offeringTable, courseTable, timetable);
    } else {
        for (Offering offering : getModel().getOfferings()) {
            offeringTable.put(new Long(offering.getId()), offering);
            for (Course course : offering.getCourses()) {
                courseTable.put(new Long(course.getId()), course);
            }
        }
    }

    List<Enrollment> bestEnrollments = new ArrayList<Enrollment>();
    List<Enrollment> currentEnrollments = new ArrayList<Enrollment>();
    if (iLoadStudents && root.element("students") != null) {
        loadStudents(root.element("students"), offeringTable, courseTable, bestEnrollments, currentEnrollments);
    }
    
    if (iLoadOfferings && root.element("constraints") != null) 
        loadLinkedSections(root.element("constraints"), offeringTable);
            
    if (!bestEnrollments.isEmpty()) assignBest(bestEnrollments);
    if (!currentEnrollments.isEmpty()) assignCurrent(currentEnrollments);
    
    if (iMoveCriticalUp) moveCriticalRequestsUp();

    sLogger.debug("Model successfully loaded.");
}
 
Example 12
Source File: CellParser.java    From ureport with Apache License 2.0 4 votes vote down vote up
@Override
public CellDefinition parse(Element element) {
	CellDefinition cell=new CellDefinition();
	cell.setName(element.attributeValue("name"));
	cell.setColumnNumber(Integer.valueOf(element.attributeValue("col")));
	cell.setRowNumber(Integer.valueOf(element.attributeValue("row")));
	cell.setLeftParentCellName(element.attributeValue("left-cell"));
	cell.setTopParentCellName(element.attributeValue("top-cell"));
	String rowSpan=element.attributeValue("row-span");
	if(StringUtils.isNotBlank(rowSpan)){
		cell.setRowSpan(Integer.valueOf(rowSpan));
	}
	String colSpan=element.attributeValue("col-span");
	if(StringUtils.isNotBlank(colSpan)){
		cell.setColSpan(Integer.valueOf(colSpan));
	}
	String expand=element.attributeValue("expand");
	if(StringUtils.isNotBlank(expand)){
		cell.setExpand(Expand.valueOf(expand));			
	}
	String fillBlankRows=element.attributeValue("fill-blank-rows");
	if(StringUtils.isNotBlank(fillBlankRows)){
		cell.setFillBlankRows(Boolean.valueOf(fillBlankRows));
		String multiple=element.attributeValue("multiple");
		if(StringUtils.isNotBlank(multiple)){
			cell.setMultiple(Integer.valueOf(multiple));
		}
	}
	cell.setLinkTargetWindow(element.attributeValue("link-target-window"));
	String linkUrl=element.attributeValue("link-url");
	cell.setLinkUrl(linkUrl);
	if(StringUtils.isNotBlank(linkUrl)){
		if(linkUrl.startsWith(ExpressionUtils.EXPR_PREFIX) && linkUrl.endsWith(ExpressionUtils.EXPR_SUFFIX)){
			String expr=linkUrl.substring(2,linkUrl.length()-1);
			Expression urlExpression=ExpressionUtils.parseExpression(expr);
			cell.setLinkUrlExpression(urlExpression);
		}
	}
	List<LinkParameter> linkParameters=null;
	List<ConditionPropertyItem> conditionPropertyItems=null;
	for(Object obj:element.elements()){
		if(!(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		Object parseData=parseValue(ele);
		if(parseData instanceof Value){
			Value value=(Value)parseData;
			cell.setValue(value);
		}else if(parseData instanceof CellStyle){
			CellStyle cellStyle=(CellStyle)parseData;
			cell.setCellStyle(cellStyle);
		}else if(parseData instanceof LinkParameter){
			if(linkParameters==null){
				linkParameters=new ArrayList<LinkParameter>();
			}
			linkParameters.add((LinkParameter)parseData);
		}else if(parseData instanceof ConditionPropertyItem){
			if(conditionPropertyItems==null){
				conditionPropertyItems=new ArrayList<ConditionPropertyItem>();
			}
			conditionPropertyItems.add((ConditionPropertyItem)parseData);
		}
	}
	if(linkParameters!=null){
		cell.setLinkParameters(linkParameters);
	}
	cell.setConditionPropertyItems(conditionPropertyItems);
	if(cell.getValue()==null){
		throw new ReportException("Cell ["+cell.getName()+"] value not define.");
	}
	return cell;
}
 
Example 13
Source File: NumberDatatype.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected NumberDatatype(Element element) {
    formatPattern = element.attributeValue("format");
    decimalSeparator = element.attributeValue("decimalSeparator");
    groupingSeparator = element.attributeValue("groupingSeparator");
}
 
Example 14
Source File: ImsCPFileResource.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Check for title and at least one resource.
 * 
 * @param unzippedDir
 * @return True if is of type.
 */
public static boolean validate(final File unzippedDir) throws AddingResourceException {
    final File fManifest = new File(unzippedDir, "imsmanifest.xml");
    final Document doc = IMSLoader.loadIMSDocument(fManifest);
    // do not throw exception already here, as it might be only a generic zip file
    if (doc == null) {
        return false;
    }

    // get all organization elements. need to set namespace
    final Element rootElement = doc.getRootElement();
    final String nsuri = rootElement.getNamespace().getURI();
    final Map nsuris = new HashMap(1);
    nsuris.put("ns", nsuri);

    // Check for organiztaion element. Must provide at least one... title gets ectracted from either
    // the (optional) <title> element or the mandatory identifier attribute.
    // This makes sure, at least a root node gets created in CPManifestTreeModel.
    final XPath meta = rootElement.createXPath("//ns:organization");
    meta.setNamespaceURIs(nsuris);
    final Element orgaEl = (Element) meta.selectSingleNode(rootElement); // TODO: accept several organizations?
    if (orgaEl == null) {
        throw new AddingResourceException("resource.no.organisation");
    }

    // Check for at least one <item> element referencing a <resource>, which will serve as an entry point.
    // This is mandatory, as we need an entry point as the user has the option of setting
    // CPDisplayController to not display a menu at all, in which case the first <item>/<resource>
    // element pair gets displayed.
    final XPath resourcesXPath = rootElement.createXPath("//ns:resources");
    resourcesXPath.setNamespaceURIs(nsuris);
    final Element elResources = (Element) resourcesXPath.selectSingleNode(rootElement);
    if (elResources == null) {
        throw new AddingResourceException("resource.no.resource"); // no <resources> element.
    }
    final XPath itemsXPath = rootElement.createXPath("//ns:item");
    itemsXPath.setNamespaceURIs(nsuris);
    final List items = itemsXPath.selectNodes(rootElement);
    if (items.size() == 0) {
        throw new AddingResourceException("resource.no.item"); // no <item> element.
    }
    for (final Iterator iter = items.iterator(); iter.hasNext();) {
        final Element item = (Element) iter.next();
        final String identifierref = item.attributeValue("identifierref");
        if (identifierref == null) {
            continue;
        }
        final XPath resourceXPath = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']");
        resourceXPath.setNamespaceURIs(nsuris);
        final Element elResource = (Element) resourceXPath.selectSingleNode(elResources);
        if (elResource == null) {
            throw new AddingResourceException("resource.no.matching.resource");
        }
        if (elResource.attribute("scormtype") != null) {
            return false;
        }
        if (elResource.attribute("scormType") != null) {
            return false;
        }
        if (elResource.attribute("SCORMTYPE") != null) {
            return false;
        }
        if (elResource.attributeValue("href") != null) {
            return true; // success.
        }
    }
    return false;
    // throw new AddingResourceException("resource.general.error");
}
 
Example 15
Source File: WebAbstractDataGrid.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean saveSettings(Element element) {
    if (!isSettingsEnabled()) {
        return false;
    }

    Element columnsElem = element.element("columns");

    String sortColumnId = null;
    String sortDirection = null;

    if (columnsElem != null) {
        sortColumnId = columnsElem.attributeValue("sortColumnId");
        sortDirection = columnsElem.attributeValue("sortDirection");
    }

    boolean commonSettingsChanged = isCommonDataGridSettingsChanged(columnsElem);
    boolean sortChanged = isSortPropertySettingsChanged(sortColumnId, sortDirection);

    boolean settingsChanged = commonSettingsChanged || sortChanged;

    if (settingsChanged) {
        if (columnsElem != null) {
            element.remove(columnsElem);
        }
        columnsElem = element.addElement("columns");

        List<Column<E>> visibleColumns = getVisibleColumns();
        for (Column<E> column : visibleColumns) {
            Element colElem = columnsElem.addElement("columns");
            colElem.addAttribute("id", column.toString());

            double width = column.getWidth();
            if (width > -1) {
                colElem.addAttribute("width", String.valueOf(width));
            }

            colElem.addAttribute("collapsed", Boolean.toString(column.isCollapsed()));
        }

        List<GridSortOrder<E>> sortOrders = component.getSortOrder();
        if (!sortOrders.isEmpty()) {
            GridSortOrder<E> sortOrder = sortOrders.get(0);

            columnsElem.addAttribute("sortColumnId", sortOrder.getSorted().getId());
            columnsElem.addAttribute("sortDirection", sortOrder.getDirection().toString());
        }
    }

    return settingsChanged;
}
 
Example 16
Source File: ButtonLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
private void loadPrimary(Button resultComponent, Element element) {
    String primary = element.attributeValue("primary");
    if (Boolean.parseBoolean(primary)) {
        resultComponent.addStyleName("c-primary-action");
    }
}
 
Example 17
Source File: FMUCHandler.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Processes a stanza that is received from another node in the FMUC set, by translating it into 'regular' MUC data.
 *
 * The provided input is expected to be a stanza received from another node in the FMUC set. It is stripped from
 * FMUC data, after which it is distributed to the local users.
 *
 * Additionally, it is sent out to all (other) FMUC nodes that are known.
 *
 * @param stanza The data to be processed.
 */
private void processRegularMUCStanza( @Nonnull final Packet stanza )
{
    final Element fmuc = stanza.getElement().element(FMUC);
    if (fmuc == null) {
        throw new IllegalArgumentException( "Provided stanza must have an 'fmuc' child element (but does not).");
    }

    final JID remoteMUC = stanza.getFrom().asBareJID();
    final JID author = new JID( fmuc.attributeValue("from") ); // TODO input validation.
    final MUCRole senderRole = room.getOccupantByFullJID( author );
    Log.trace("(room: '{}'): Processing stanza from remote FMUC peer '{}' as regular room traffic. Sender of stanza: {}", room.getJID(), remoteMUC, author );

    // Distribute. Note that this will distribute both to the local node, as well as to all FMUC nodes in the the FMUC set.
    if ( stanza instanceof Presence ) {
        RemoteFMUCNode remoteFMUCNode = inboundJoins.get(remoteMUC);
        if ( remoteFMUCNode == null && outboundJoin != null && remoteMUC.equals(outboundJoin.getPeer())) {
            remoteFMUCNode = outboundJoin;
        }
        if ( remoteFMUCNode != null )
        {
            final boolean isLeave = ((Presence) stanza).getType() == Presence.Type.unavailable;
            final boolean isJoin = ((Presence) stanza).isAvailable();

            if ( isLeave )
            {
                Log.trace("(room: '{}'): Occupant '{}' left room on remote FMUC peer '{}'", room.getJID(), author, remoteMUC );
                makeRemoteOccupantLeaveRoom( (Presence) stanza );
                remoteFMUCNode.removeOccupant(author); // Remove occupant only after the leave stanzas have been sent, otherwise the author is (no longer) recognized as an occupant of the particular node when the leave is being processed.

                // The joined room confirms that the joining room has left the set by sending a presence stanza from the bare JID
                // of the joined room to the bare JID of the joining room with an FMUC payload containing an element 'left'.
                if ( remoteFMUCNode instanceof InboundJoin && remoteFMUCNode.occupants.isEmpty() ) {
                    Log.trace("(room: '{}'): Last occupant that joined on remote FMUC peer '{}' has now left the room. The peer has left the FMUC node set.", room.getJID(), remoteMUC );
                    final Presence leaveFMUCSet = new Presence();
                    leaveFMUCSet.setTo( remoteMUC );
                    leaveFMUCSet.setFrom( room.getJID() );
                    leaveFMUCSet.getElement().addElement( FMUC ).addElement( "left" );
                    inboundJoins.remove(remoteMUC);

                    router.route( leaveFMUCSet );
                }
            } else if ( isJoin ) {
                Log.trace("(room: '{}'): Occupant '{}' joined room on remote FMUC peer '{}'", room.getJID(), author, remoteMUC );
                remoteFMUCNode.addOccupant(author);
                makeRemoteOccupantJoinRoom( (Presence) stanza );
            } else {
                // FIXME implement sharing of presence.
                Log.error("Processing of presence stanzas received from other FMUC nodes is pending implementation! Ignored stanza: {}", stanza.toXML(), new UnsupportedOperationException());
            }
        }
        else
        {
            Log.warn( "Unable to process stanza: {}", stanza.toXML() );
        }
    } else {
        // Strip all FMUC data.
        final Packet stripped = createCopyWithoutFMUC( stanza );

        // The 'stripped' stanza is going to be distributed locally. Act as if it originates from a local user, instead of the remote FMUC one.
        final JID from;
        if ( author != null ) {
            from = senderRole.getRoleAddress();
        } else {
            Log.trace("(room: '{}'): FMUC stanza did not have 'from' value. Using room JID instead.", room.getJID() );
            from = room.getJID();
        }
        stripped.setFrom( from );
        stripped.setTo( room.getJID() );

        room.send( stripped, senderRole );
    }
}
 
Example 18
Source File: DoubleValidator.java    From cuba with Apache License 2.0 4 votes vote down vote up
public DoubleValidator(Element element, String messagesPack) {
    message = element.attributeValue("message");
    onlyPositive = element.attributeValue("onlyPositive");
    this.messagesPack = messagesPack;
}
 
Example 19
Source File: AbstractTableLoader.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void loadTextSelectionEnabled(Table table, Element element) {
    String textSelectionEnabled = element.attributeValue("textSelectionEnabled");
    if (StringUtils.isNotEmpty(textSelectionEnabled)) {
        table.setTextSelectionEnabled(Boolean.parseBoolean(textSelectionEnabled));
    }
}
 
Example 20
Source File: XmlText.java    From ats-framework with Apache License 2.0 3 votes vote down vote up
/**
 * @param xpath XPath , pointing to a XML element
 * @param name the name of the attribute
 * @return the value of the attribute
 * @throws XMLException
 */
@PublicAtsApi
public String getAttribute(
                            String xpath,
                            String name ) throws XMLException {

    if (StringUtils.isNullOrEmpty(xpath)) {

        throw new XMLException("Null/empty xpath is not allowed.");

    }

    if (StringUtils.isNullOrEmpty(name)) {

        throw new XMLException("Null/empty attribute name is not allowed.");

    }

    Element element = findElement(xpath);

    if (element == null) {

        throw new XMLException("'" + xpath + "' is not a valid path");

    }

    String attributeValue = element.attributeValue(name);

    if (attributeValue == null) {

        throw new XMLException("'" + name + "' attribute is not found for XML element with xpath '"
                               + xpath + "'.");

    }

    return attributeValue;
}